Skip to content

Commit aeabc16

Browse files
committed
When searching for backend status iterate over the index in the LocalPgBackendStatus array, not over BackendId for v16 or ProcNumber for 16+.
BackendId may not be equal to the index +1 in the LocalPgBackendStatus array as well as ProcNumber may not be equal the index.
1 parent 25bd499 commit aeabc16

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

pg_query_state.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,16 @@ search_be_status(int pid)
365365

366366
for (beid = 1; beid <= pgstat_fetch_stat_numbackends(); beid++)
367367
{
368-
#if PG_VERSION_NUM >= 170000
369-
PgBackendStatus *be_status = pgstat_get_beentry_by_proc_number(beid);
370-
#elif PG_VERSION_NUM >= 160000
371-
PgBackendStatus *be_status = pgstat_get_beentry_by_backend_id(beid);
368+
#if PG_VERSION_NUM >= 160000
369+
LocalPgBackendStatus *lbe_status = pgstat_get_local_beentry_by_index(beid);
370+
PgBackendStatus *be_status;
371+
372+
Assert(lbe_status);
373+
#ifndef PGPRO_STD
374+
be_status = &lbe_status->backendStatus;
375+
#else
376+
be_status = lbe_status->backendStatus;
377+
#endif
372378
#else
373379
PgBackendStatus *be_status = pgstat_fetch_stat_beentry(beid);
374380
#endif

0 commit comments

Comments
 (0)