agora inbox for [email protected]
help / color / mirror / Atom feedFrom: Nathan Bossart <[email protected]>
Subject: [PATCH v2 2/2] fix pg_stat_get_backend_subxact to use real backend id
Date: Thu, 24 Aug 2023 07:58:01 -0700
---
src/backend/utils/activity/backend_status.c | 36 +++++++++++++++------
src/backend/utils/adt/pgstatfuncs.c | 2 +-
src/include/utils/backend_status.h | 1 +
3 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/src/backend/utils/activity/backend_status.c b/src/backend/utils/activity/backend_status.c
index aea05a9014..d5babd9fb0 100644
--- a/src/backend/utils/activity/backend_status.c
+++ b/src/backend/utils/activity/backend_status.c
@@ -1088,9 +1088,33 @@ cmp_lbestatus(const void *a, const void *b)
*/
PgBackendStatus *
pgstat_get_beentry_by_backend_id(BackendId beid)
+{
+ LocalPgBackendStatus *ret = pgstat_get_local_beentry_by_backend_id(beid);
+
+ if (ret)
+ return &ret->backendStatus;
+
+ return NULL;
+}
+
+
+/* ----------
+ * pgstat_get_local_beentry_by_backend_id() -
+ *
+ * Like pgstat_get_beentry_by_backend_id() but with locally computed additions
+ * (like xid and xmin values of the backend)
+ *
+ * The beid argument is the BackendId of the desired session
+ * (note that this is unlike pgstat_get_local_beentry_by_index()).
+ *
+ * NB: caller is responsible for checking if the user is permitted to see this
+ * info (especially the querystring).
+ * ----------
+ */
+LocalPgBackendStatus *
+pgstat_get_local_beentry_by_backend_id(BackendId beid)
{
LocalPgBackendStatus key;
- LocalPgBackendStatus *ret;
pgstat_read_current_status();
@@ -1099,14 +1123,8 @@ pgstat_get_beentry_by_backend_id(BackendId beid)
* bsearch() to search it efficiently.
*/
key.backend_id = beid;
- ret = (LocalPgBackendStatus *) bsearch(&key, localBackendStatusTable,
- localNumBackends,
- sizeof(LocalPgBackendStatus),
- cmp_lbestatus);
- if (ret)
- return &ret->backendStatus;
-
- return NULL;
+ return bsearch(&key, localBackendStatusTable, localNumBackends,
+ sizeof(LocalPgBackendStatus), cmp_lbestatus);
}
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 7deefed5ab..62d327bb92 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -727,7 +727,7 @@ pg_stat_get_backend_subxact(PG_FUNCTION_ARGS)
BlessTupleDesc(tupdesc);
- if ((local_beentry = pgstat_get_local_beentry_by_index(beid)) != NULL)
+ if ((local_beentry = pgstat_get_local_beentry_by_backend_id(beid)) != NULL)
{
/* Fill values and NULLs */
values[0] = Int32GetDatum(local_beentry->backend_subxact_count);
diff --git a/src/include/utils/backend_status.h b/src/include/utils/backend_status.h
index e53098ec9e..a996c7fd23 100644
--- a/src/include/utils/backend_status.h
+++ b/src/include/utils/backend_status.h
@@ -334,6 +334,7 @@ extern uint64 pgstat_get_my_query_id(void);
*/
extern int pgstat_fetch_stat_numbackends(void);
extern PgBackendStatus *pgstat_get_beentry_by_backend_id(BackendId beid);
+extern LocalPgBackendStatus *pgstat_get_local_beentry_by_backend_id(BackendId beid);
extern LocalPgBackendStatus *pgstat_get_local_beentry_by_index(int beid);
extern char *pgstat_clip_activity(const char *raw_activity);
--
2.25.1
--gKMricLos+KVdGMg--
view thread (16+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [PATCH v2 2/2] fix pg_stat_get_backend_subxact to use real backend id
In-Reply-To: <no-message-id-1853315@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox