aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/pgstatfuncs.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2014-02-25 12:34:04 -0500
committerRobert Haas <rhaas@postgresql.org>2014-02-25 12:34:04 -0500
commitdd1a3bccca241a998b4ebf39d67202698e5fa599 (patch)
treeac25477cab559d842e406a1f6ba878257c694dc4 /src/backend/utils/adt/pgstatfuncs.c
parent278c94209b90b8e241f64ea4ce2d955b63b1f5d7 (diff)
downloadpostgresql-dd1a3bccca241a998b4ebf39d67202698e5fa599.tar.gz
postgresql-dd1a3bccca241a998b4ebf39d67202698e5fa599.zip
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.
Diffstat (limited to 'src/backend/utils/adt/pgstatfuncs.c')
-rw-r--r--src/backend/utils/adt/pgstatfuncs.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index a4f31cfc7fc..140704f97ca 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -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())
{