From 86ff66807ca60e96ff97ef10829a32c5556643a1 Mon Sep 17 00:00:00 2001 From: Matthias van de Meent Date: Mon, 3 Aug 2026 12:01:50 +0200 Subject: [PATCH v1 2/2] nocfbot Instrumentation for GetSnapshotReuseUnlocked. --- src/backend/storage/ipc/procarray.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index 5025776a8c0..cf65b39025e 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -317,6 +317,11 @@ static GlobalVisState GlobalVisCatalogRels; static GlobalVisState GlobalVisDataRels; static GlobalVisState GlobalVisTempRels; +static int64 count_unlocked = 0; +static int64 count_xmin = 0; +static int64 count_completion = 0; +static int64 count_uninitialized = 0; + /* * This backend's RecentXmin at the last time the accurate xmin horizon was * recomputed, or InvalidTransactionId if it has not. Used to limit how many @@ -644,6 +649,9 @@ ProcArrayRemove(PGPROC *proc, TransactionId latestXid) */ LWLockRelease(XidGenLock); LWLockRelease(ProcArrayLock); + + elog(LOG, "Unlocked Snapshot Reuse: xmin: " INT64_FORMAT ", uninitialized: " INT64_FORMAT ", completion: " INT64_FORMAT ", unlocked: " INT64_FORMAT, + count_xmin, count_uninitialized, count_completion, count_unlocked); } @@ -2029,12 +2037,14 @@ GetSnapshotReuseUnlocked(Snapshot snapshot, bool *try_reuse) if (!TransactionIdIsValid(MyProc->xmin)) { + count_xmin++; *try_reuse = true; return false; } if (unlikely(snapshot->snapXactCompletionCount == 0)) { + count_uninitialized++; *try_reuse = false; return false; } @@ -2045,10 +2055,12 @@ GetSnapshotReuseUnlocked(Snapshot snapshot, bool *try_reuse) if (snapshot->snapXactCompletionCount != completions) { + count_completion++; *try_reuse = false; return false; } + count_unlocked++; pg_memory_barrier(); RecentXmin = snapshot->xmin; -- 2.50.1 (Apple Git-155)