mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +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:
@ -536,7 +536,7 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
|
||||
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
|
||||
|
||||
tupdesc = CreateTemplateTupleDesc(14, false);
|
||||
tupdesc = CreateTemplateTupleDesc(16, false);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "datid",
|
||||
OIDOID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "pid",
|
||||
@ -565,6 +565,10 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
TEXTOID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 14, "client_port",
|
||||
INT4OID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 15, "backend_xid",
|
||||
XIDOID, -1, 0);
|
||||
TupleDescInitEntry(tupdesc, (AttrNumber) 16, "backend_xmin",
|
||||
XIDOID, -1, 0);
|
||||
|
||||
funcctx->tuple_desc = BlessTupleDesc(tupdesc);
|
||||
|
||||
@ -616,9 +620,10 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
if (funcctx->call_cntr < funcctx->max_calls)
|
||||
{
|
||||
/* for each row */
|
||||
Datum values[14];
|
||||
bool nulls[14];
|
||||
Datum values[16];
|
||||
bool nulls[16];
|
||||
HeapTuple tuple;
|
||||
LocalPgBackendStatus *local_beentry;
|
||||
PgBackendStatus *beentry;
|
||||
|
||||
MemSet(values, 0, sizeof(values));
|
||||
@ -627,12 +632,14 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
if (*(int *) (funcctx->user_fctx) > 0)
|
||||
{
|
||||
/* Get specific pid slot */
|
||||
beentry = pgstat_fetch_stat_beentry(*(int *) (funcctx->user_fctx));
|
||||
local_beentry = pgstat_fetch_stat_local_beentry(*(int *) (funcctx->user_fctx));
|
||||
beentry = &local_beentry->backendStatus;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Get the next one in the list */
|
||||
beentry = pgstat_fetch_stat_beentry(funcctx->call_cntr + 1); /* 1-based index */
|
||||
local_beentry = pgstat_fetch_stat_local_beentry(funcctx->call_cntr + 1); /* 1-based index */
|
||||
beentry = &local_beentry->backendStatus;
|
||||
}
|
||||
if (!beentry)
|
||||
{
|
||||
@ -657,6 +664,16 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
|
||||
else
|
||||
nulls[3] = true;
|
||||
|
||||
if (TransactionIdIsValid(local_beentry->backend_xid))
|
||||
values[14] = TransactionIdGetDatum(local_beentry->backend_xid);
|
||||
else
|
||||
nulls[14] = true;
|
||||
|
||||
if (TransactionIdIsValid(local_beentry->backend_xmin))
|
||||
values[15] = TransactionIdGetDatum(local_beentry->backend_xmin);
|
||||
else
|
||||
nulls[15] = true;
|
||||
|
||||
/* Values only available to same user or superuser */
|
||||
if (superuser() || beentry->st_userid == GetUserId())
|
||||
{
|
||||
|
Reference in New Issue
Block a user