mirror of
https://github.com/postgres/postgres.git
synced 2025-11-15 03:41:20 +03:00
Show xid and xmin in pg_stat_activity and pg_stat_replication.
Christian Kruse, reviewed by Andres Freund and myself, with further minor adjustments by me.
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "storage/shmem.h"
|
||||
#include "storage/sinvaladt.h"
|
||||
#include "storage/spin.h"
|
||||
#include "access/transam.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -400,6 +401,37 @@ BackendIdGetProc(int backendID)
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* BackendIdGetTransactionIds
|
||||
* Get the xid and xmin of the backend. The result may be out of date
|
||||
* arbitrarily quickly, so the caller must be careful about how this
|
||||
* information is used.
|
||||
*/
|
||||
void
|
||||
BackendIdGetTransactionIds(int backendID, TransactionId *xid, TransactionId *xmin)
|
||||
{
|
||||
ProcState *stateP;
|
||||
SISeg *segP = shmInvalBuffer;
|
||||
PGXACT *xact;
|
||||
|
||||
*xid = InvalidTransactionId;
|
||||
*xmin = InvalidTransactionId;
|
||||
|
||||
/* Need to lock out additions/removals of backends */
|
||||
LWLockAcquire(SInvalWriteLock, LW_SHARED);
|
||||
|
||||
if (backendID > 0 && backendID <= segP->lastBackend)
|
||||
{
|
||||
stateP = &segP->procState[backendID - 1];
|
||||
xact = &ProcGlobal->allPgXact[stateP->proc->pgprocno];
|
||||
|
||||
*xid = xact->xid;
|
||||
*xmin = xact->xmin;
|
||||
}
|
||||
|
||||
LWLockRelease(SInvalWriteLock);
|
||||
}
|
||||
|
||||
/*
|
||||
* SIInsertDataEntries
|
||||
* Add new invalidation message(s) to the buffer.
|
||||
|
||||
Reference in New Issue
Block a user