mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
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
9aea73fc61, 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.pg@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Nazir Bilal Yavuz <byavuz81@gmail.com>
Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: https://postgr.es/m/Z3zqc4o09dM/Ezyz@ip-10-97-1-34.eu-west-3.compute.internal
This commit is contained in:
@@ -1609,8 +1609,8 @@ pg_stat_get_backend_io(PG_FUNCTION_ARGS)
|
||||
/*
|
||||
* pg_stat_wal_build_tuple
|
||||
*
|
||||
* Helper routine for pg_stat_get_wal() returning one tuple based on the
|
||||
* contents of wal_counters.
|
||||
* Helper routine for pg_stat_get_wal() and pg_stat_get_backend_wal()
|
||||
* returning one tuple based on the contents of wal_counters.
|
||||
*/
|
||||
static Datum
|
||||
pg_stat_wal_build_tuple(PgStat_WalCounters wal_counters,
|
||||
@@ -1659,6 +1659,28 @@ pg_stat_wal_build_tuple(PgStat_WalCounters wal_counters,
|
||||
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns WAL statistics for a backend with given PID.
|
||||
*/
|
||||
Datum
|
||||
pg_stat_get_backend_wal(PG_FUNCTION_ARGS)
|
||||
{
|
||||
int pid;
|
||||
PgStat_Backend *backend_stats;
|
||||
PgStat_WalCounters bktype_stats;
|
||||
|
||||
pid = PG_GETARG_INT32(0);
|
||||
backend_stats = pgstat_fetch_stat_backend_by_pid(pid, NULL);
|
||||
|
||||
if (!backend_stats)
|
||||
PG_RETURN_NULL();
|
||||
|
||||
bktype_stats = backend_stats->wal_counters;
|
||||
|
||||
/* save tuples with data from this PgStat_WalCounters */
|
||||
return (pg_stat_wal_build_tuple(bktype_stats, backend_stats->stat_reset_timestamp));
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns statistics of WAL activity
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user