Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd0fe304

Browse files
Use actual backend IDs in pg_stat_get_backend_subxact().
Unlike the other pg_stat_get_backend* functions,pg_stat_get_backend_subxact() looks up the backend entry by usingits integer argument as a 1-based index in an internal array. Theother functions look for the entry with the matching sessionbackend ID. These numbers often match, but that isn't reliablytrue.This commit resolves this discrepancy by introducingpgstat_get_local_beentry_by_backend_id() and using it inpg_stat_get_backend_subxact(). We cannot usepgstat_get_beentry_by_backend_id() because it returns aPgBackendStatus, which lacks the locally computed additionsavailable in LocalPgBackendStatus that are required bypg_stat_get_backend_subxact().Author: Ian BarwickReviewed-by: Sami Imseih, Michael Paquier, Robert HaasDiscussion:https://postgr.es/m/CAB8KJ%3Dj-ACb3H4L9a_b3ZG3iCYDW5aEu3WsPAzkm2S7JzS1Few%40mail.gmail.comBackpatch-through: 16
1 parent3d51cb5 commitd0fe304

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

‎src/backend/utils/activity/backend_status.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,9 +1088,33 @@ cmp_lbestatus(const void *a, const void *b)
10881088
*/
10891089
PgBackendStatus*
10901090
pgstat_get_beentry_by_backend_id(BackendIdbeid)
1091+
{
1092+
LocalPgBackendStatus*ret=pgstat_get_local_beentry_by_backend_id(beid);
1093+
1094+
if (ret)
1095+
return&ret->backendStatus;
1096+
1097+
returnNULL;
1098+
}
1099+
1100+
1101+
/* ----------
1102+
* pgstat_get_local_beentry_by_backend_id() -
1103+
*
1104+
*Like pgstat_get_beentry_by_backend_id() but with locally computed additions
1105+
*(like xid and xmin values of the backend)
1106+
*
1107+
*The beid argument is the BackendId of the desired session
1108+
*(note that this is unlike pgstat_get_local_beentry_by_index()).
1109+
*
1110+
*NB: caller is responsible for checking if the user is permitted to see this
1111+
*info (especially the querystring).
1112+
* ----------
1113+
*/
1114+
LocalPgBackendStatus*
1115+
pgstat_get_local_beentry_by_backend_id(BackendIdbeid)
10911116
{
10921117
LocalPgBackendStatuskey;
1093-
LocalPgBackendStatus*ret;
10941118

10951119
pgstat_read_current_status();
10961120

@@ -1099,14 +1123,8 @@ pgstat_get_beentry_by_backend_id(BackendId beid)
10991123
* bsearch() to search it efficiently.
11001124
*/
11011125
key.backend_id=beid;
1102-
ret= (LocalPgBackendStatus*)bsearch(&key,localBackendStatusTable,
1103-
localNumBackends,
1104-
sizeof(LocalPgBackendStatus),
1105-
cmp_lbestatus);
1106-
if (ret)
1107-
return&ret->backendStatus;
1108-
1109-
returnNULL;
1126+
returnbsearch(&key,localBackendStatusTable,localNumBackends,
1127+
sizeof(LocalPgBackendStatus),cmp_lbestatus);
11101128
}
11111129

11121130

‎src/backend/utils/adt/pgstatfuncs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ pg_stat_get_backend_subxact(PG_FUNCTION_ARGS)
727727

728728
BlessTupleDesc(tupdesc);
729729

730-
if ((local_beentry=pgstat_get_local_beentry_by_index(beid))!=NULL)
730+
if ((local_beentry=pgstat_get_local_beentry_by_backend_id(beid))!=NULL)
731731
{
732732
/* Fill values and NULLs */
733733
values[0]=Int32GetDatum(local_beentry->backend_subxact_count);

‎src/include/utils/backend_status.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ extern uint64 pgstat_get_my_query_id(void);
334334
*/
335335
externintpgstat_fetch_stat_numbackends(void);
336336
externPgBackendStatus*pgstat_get_beentry_by_backend_id(BackendIdbeid);
337+
externLocalPgBackendStatus*pgstat_get_local_beentry_by_backend_id(BackendIdbeid);
337338
externLocalPgBackendStatus*pgstat_get_local_beentry_by_index(intidx);
338339
externchar*pgstat_clip_activity(constchar*raw_activity);
339340

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp