pgsql: Add WAL data to backend statistics

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add WAL data to backend statistics
Date: 2025-03-11 00:05:42
Message-ID: E1trn7u-001q2p-13@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add WAL data to backend statistics

This commit adds per-backend WAL statistics, providing the same
information as pg_stat_wal, except that it is now possible to know how
much WAL activity is happening in each backend rather than an overall
aggregate of all the activity. Like pg_stat_wal, the implementation
relies on pgWalUsage, tracking the difference of activity between two
reports to pgstats.

This data can be retrieved with a new system function called
pg_stat_get_backend_wal(), that returns one tuple based on the PID
provided in input. Like pg_stat_get_backend_io(), this is useful when
joined with pg_stat_activity to get a live picture of the WAL generated
for each running backend, showing how the activity is [un]balanced.

pgstat_flush_backend() gains a new flag value, able to control the flush
of the WAL stats.

This commit relies mostly on the infrastructure provided by
9aea73fc61d4, that has introduced backend statistics.

Bump catalog version. A bump of PGSTAT_FILE_FORMAT_ID is not required,
as backend stats do not persist on disk.

Author: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Reviewed-by: Michael Paquier <michael(at)paquier(dot)xyz>
Reviewed-by: Nazir Bilal Yavuz <byavuz81(at)gmail(dot)com>
Reviewed-by: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Discussion: https://postgr.es/m/Z3zqc4o09dM/Ezyz(at)ip-10-97-1-34(dot)eu-west-3(dot)compute(dot)internal

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/76def4cdd7c2b32d19e950a160f834392ea51744

Modified Files
--------------
doc/src/sgml/monitoring.sgml | 19 +++++++
src/backend/utils/activity/pgstat_backend.c | 87 ++++++++++++++++++++++++++++-
src/backend/utils/activity/pgstat_wal.c | 1 +
src/backend/utils/adt/pgstatfuncs.c | 26 ++++++++-
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_proc.dat | 7 +++
src/include/pgstat.h | 41 ++++++++------
src/include/utils/pgstat_internal.h | 3 +-
src/test/regress/expected/stats.out | 17 +++++-
src/test/regress/sql/stats.sql | 9 ++-
10 files changed, 185 insertions(+), 27 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2025-03-11 07:48:00 pgsql: refactor: re-add ATExecAlterChildConstr()
Previous Message Andres Freund 2025-03-10 23:34:00 Re: pgsql: tests: Fix race condition in postmaster/002_connection_limits