pgsql: Use actual backend IDs in pg_stat_get_backend_subxact(). - Mailing list pgsql-committers

From Nathan Bossart
Subject pgsql: Use actual backend IDs in pg_stat_get_backend_subxact().
Date
Msg-id E1qbT3O-001jDd-Sw@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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 using
its integer argument as a 1-based index in an internal array.  The
other functions look for the entry with the matching session
backend ID.  These numbers often match, but that isn't reliably
true.

This commit resolves this discrepancy by introducing
pgstat_get_local_beentry_by_backend_id() and using it in
pg_stat_get_backend_subxact().  We cannot use
pgstat_get_beentry_by_backend_id() because it returns a
PgBackendStatus, which lacks the locally computed additions
available in LocalPgBackendStatus that are required by
pg_stat_get_backend_subxact().

Author: Ian Barwick
Reviewed-by: Sami Imseih, Michael Paquier, Robert Haas
Discussion: https://postgr.es/m/CAB8KJ%3Dj-ACb3H4L9a_b3ZG3iCYDW5aEu3WsPAzkm2S7JzS1Few%40mail.gmail.com
Backpatch-through: 16

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/133654a05b4367e3e70f7cfe496a4b9386674fcf

Modified Files
--------------
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(-)


pgsql-committers by date:

Previous
From: Peter Eisentraut
Date:
Subject: pgsql: Fix possible compiler warning
Next
From: Michael Paquier
Date:
Subject: pgsql: Fix some shadow variables in src/backend/replication/