1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-04 20:11:56 +03:00

Add wal_fpi_bytes to pg_stat_wal and pg_stat_get_backend_wal()

This new counter, called "wal_fpi_bytes", tracks the total amount in
bytes of full page images (FPIs) generated in WAL.  This data becomes
available globally via pg_stat_wal, and for backend statistics via
pg_stat_get_backend_wal().

Previously, this information could only be retrieved with pg_waldump or
pg_walinspect, which may not be available depending on the environment,
and are expensive to execute.  It offers hints about how much FPIs
impact the WAL generated, which could be a large percentage for some
workloads, as well as the effects of wal_compression or page holes.

Bump catalog version.
Bump PGSTAT_FILE_FORMAT_ID, due to the addition of wal_fpi_bytes in
PgStat_WalCounters.

Author: Shinya Kato <shinya11.kato@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAOzEurQtZEAfg6P0kU3Wa-f9BWQOi0RzJEMPN56wNTOmJLmfaQ@mail.gmail.com
This commit is contained in:
Michael Paquier
2025-10-28 16:21:51 +09:00
parent 3e8e05596a
commit f9a09aa295
12 changed files with 46 additions and 15 deletions

View File

@@ -1637,7 +1637,7 @@ static Datum
pg_stat_wal_build_tuple(PgStat_WalCounters wal_counters,
TimestampTz stat_reset_timestamp)
{
#define PG_STAT_WAL_COLS 5
#define PG_STAT_WAL_COLS 6
TupleDesc tupdesc;
Datum values[PG_STAT_WAL_COLS] = {0};
bool nulls[PG_STAT_WAL_COLS] = {0};
@@ -1651,9 +1651,11 @@ pg_stat_wal_build_tuple(PgStat_WalCounters wal_counters,
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 3, "wal_bytes",
NUMERICOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 4, "wal_buffers_full",
TupleDescInitEntry(tupdesc, (AttrNumber) 4, "wal_fpi_bytes",
NUMERICOID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 5, "wal_buffers_full",
INT8OID, -1, 0);
TupleDescInitEntry(tupdesc, (AttrNumber) 5, "stats_reset",
TupleDescInitEntry(tupdesc, (AttrNumber) 6, "stats_reset",
TIMESTAMPTZOID, -1, 0);
BlessTupleDesc(tupdesc);
@@ -1669,12 +1671,18 @@ pg_stat_wal_build_tuple(PgStat_WalCounters wal_counters,
ObjectIdGetDatum(0),
Int32GetDatum(-1));
values[3] = Int64GetDatum(wal_counters.wal_buffers_full);
snprintf(buf, sizeof buf, UINT64_FORMAT, wal_counters.wal_fpi_bytes);
values[3] = DirectFunctionCall3(numeric_in,
CStringGetDatum(buf),
ObjectIdGetDatum(0),
Int32GetDatum(-1));
values[4] = Int64GetDatum(wal_counters.wal_buffers_full);
if (stat_reset_timestamp != 0)
values[4] = TimestampTzGetDatum(stat_reset_timestamp);
values[5] = TimestampTzGetDatum(stat_reset_timestamp);
else
nulls[4] = true;
nulls[5] = true;
/* Returns the record as Datum */
PG_RETURN_DATUM(HeapTupleGetDatum(heap_form_tuple(tupdesc, values, nulls)));