diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 07e4fd85305..1032365f0a5 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -589,6 +589,10 @@ AssignTransactionId(TransactionState s) XactLockTableInsert(s->transactionId); + LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE); + MyProc->xltwSet = true; + LWLockRelease(ProcArrayLock); + CurrentResourceOwner = currentOwner; /* diff --git a/src/backend/storage/ipc/procarray.c b/src/backend/storage/ipc/procarray.c index fa9f297ac2d..b2a092641b6 100644 --- a/src/backend/storage/ipc/procarray.c +++ b/src/backend/storage/ipc/procarray.c @@ -419,6 +419,10 @@ ProcArrayEndTransaction(PGPROC *proc, TransactionId latestXid) } else ProcArrayGroupClearXid(proc, latestXid); + + LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE); + MyProc->xltwSet = false; + LWLockRelease(ProcArrayLock); } else { @@ -2001,6 +2005,7 @@ GetRunningTransactionData(void) { int pgprocno = arrayP->pgprocnos[index]; volatile PGXACT *pgxact = &allPgXact[pgprocno]; + volatile PGPROC *proc = &allProcs[pgprocno]; TransactionId xid; /* Fetch xid just once - see GetNewTransactionId */ @@ -2010,7 +2015,7 @@ GetRunningTransactionData(void) * We don't need to store transactions that don't have a TransactionId * yet because they will not show as running on a standby server. */ - if (!TransactionIdIsValid(xid)) + if (!TransactionIdIsValid(xid) || !proc->xltwSet) continue; xids[count++] = xid; diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 5f6727d5014..e83e12fa6b5 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -381,6 +381,7 @@ InitProcess(void) MyProc->lwWaitMode = 0; MyProc->waitLock = NULL; MyProc->waitProcLock = NULL; + MyProc->xltwSet = false; #ifdef USE_ASSERT_CHECKING { int i; diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h index 205f4845108..e993811c1ef 100644 --- a/src/include/storage/proc.h +++ b/src/include/storage/proc.h @@ -138,6 +138,7 @@ struct PGPROC LOCKMODE waitLockMode; /* type of lock we're waiting for */ LOCKMASK heldLocks; /* bitmask for lock types already held on this * lock object by this backend */ + bool xltwSet; /* * Info to allow us to wait for synchronous replication, if needed.