pgsql: Handle auxiliary processes in SQL functions of backend statistic

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Handle auxiliary processes in SQL functions of backend statistic
Date: 2025-03-03 01:01:01
Message-ID: E1touB3-000XLI-1X@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Handle auxiliary processes in SQL functions of backend statistics

This commit impacts the following SQL functions, authorizing the access
to the PGPROC entries of auxiliary processes when attempting to fetch or
reset backend-level pgstats entries:
- pg_stat_reset_backend_stats()
- pg_stat_get_backend_io()

This is relevant since a051e71e28a1 for at least the WAL summarizer, WAL
receiver and WAL writer processes, that has changed the backend
statistics to authorize these three following the addition of WAL I/O
statistics in pg_stat_io and backend statistics. The code is more
flexible with future changes written this way, adapting automatically to
any updates done in pgstat_tracks_backend_bktype().

While on it, pgstat_report_wal() gains a call to pgstat_flush_backend(),
making sure that backend I/O statistics are updated when calling this
routine. This makes the statistics report correctly for the WAL writer.
WAL receiver and WAL summarizer do not call pgstat_report_wal() yet
(spoiler: both should). It should be possible to lift some of the
existing restrictions for other auxiliary processes, as well, but this
is left as future work.

Reported-by: Rahila Syed <rahilasyed90(at)gmail(dot)com>
Author: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAH2L28v9BwN8_y0k6FQ591=0g2Hj_esHLGj3bP38c9nmVykoiA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/3f1db99bfabbb9d4afc41f362d9801512f4c7c65

Modified Files
--------------
src/backend/utils/activity/pgstat_backend.c | 17 ++++++++---------
src/backend/utils/activity/pgstat_wal.c | 1 +
src/backend/utils/adt/pgstatfuncs.c | 23 +++++++++++++++++------
3 files changed, 26 insertions(+), 15 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Robins Tharakan 2025-03-03 13:02:37 Re: pgsql: Track unpruned relids to avoid processing pruned relations
Previous Message Fujii Masao 2025-03-03 00:16:31 pgsql: postgres_fdw: Extend postgres_fdw_get_connections to return remo