summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/pgstatfuncs.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2022-12-19 14:43:09 -0500
committerRobert Haas <rhaas@postgresql.org>2022-12-19 14:43:09 -0500
commit10ea0f924a2788f9e701d6213745aaa5ca3efb8a (patch)
tree7b59764577d935ade39514b0c500237acb38a527 /src/backend/utils/adt/pgstatfuncs.c
parent7122f9d5437789312cb0a7e26e853bb8d2e57add (diff)
downloadpostgresql-10ea0f924a2788f9e701d6213745aaa5ca3efb8a.tar.gz
Expose some information about backend subxact status.
A new function pg_stat_get_backend_subxact() can be used to get information about the number of subtransactions in the cache of a particular backend and whether that cache has overflowed. This can be useful for tracking down performance problems that can result from overflowed snapshots. Dilip Kumar, reviewed by Zhihong Yu, Nikolay Samokhvalov, Justin Pryzby, Nathan Bossart, Ashutosh Sharma, Julien Rouhaud. Additional design comments from Andres Freund, Tom Lane, Bruce Momjian, and David G. Johnston. Discussion: http://postgr.es/m/CAFiTN-ut0uwkRJDQJeDPXpVyTWD46m3gt3JDToE02hTfONEN=Q@mail.gmail.com
Diffstat (limited to 'src/backend/utils/adt/pgstatfuncs.c')
-rw-r--r--src/backend/utils/adt/pgstatfuncs.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 04a5a99002..46f98fd67f 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -687,6 +687,44 @@ pg_stat_get_backend_userid(PG_FUNCTION_ARGS)
PG_RETURN_OID(beentry->st_userid);
}
+Datum
+pg_stat_get_backend_subxact(PG_FUNCTION_ARGS)
+{
+#define PG_STAT_GET_SUBXACT_COLS 2
+ TupleDesc tupdesc;
+ Datum values[PG_STAT_GET_SUBXACT_COLS];
+ bool nulls[PG_STAT_GET_SUBXACT_COLS];
+ int32 beid = PG_GETARG_INT32(0);
+ LocalPgBackendStatus *local_beentry;
+
+ /* Initialise values and NULL flags arrays */
+ MemSet(values, 0, sizeof(values));
+ MemSet(nulls, 0, sizeof(nulls));
+
+ /* Initialise attributes information in the tuple descriptor */
+ tupdesc = CreateTemplateTupleDesc(PG_STAT_GET_SUBXACT_COLS);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 1, "subxact_count",
+ INT4OID, -1, 0);
+ TupleDescInitEntry(tupdesc, (AttrNumber) 2, "subxact_overflow",
+ BOOLOID, -1, 0);
+
+ BlessTupleDesc(tupdesc);
+
+ if ((local_beentry = pgstat_fetch_stat_local_beentry(beid)) != NULL)
+ {
+ /* Fill values and NULLs */
+ values[0] = Int32GetDatum(local_beentry->backend_subxact_count);
+ values[1] = BoolGetDatum(local_beentry->backend_subxact_overflowed);
+ }
+ else
+ {
+ nulls[0] = true;
+ nulls[1] = true;
+ }
+
+ /* Returns the record as Datum */
+ PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
+}
Datum
pg_stat_get_backend_activity(PG_FUNCTION_ARGS)