From 1a1f7d972ef7be24e5adf76c2ae201d6f4b6e396 Mon Sep 17 00:00:00 2001 From: Shinya Kato Date: Sat, 18 Oct 2025 16:28:05 +0900 Subject: [PATCH v1 2/3] Add wal_fpi_bytes_[un]compressed to EXPLAIN (WAL) --- doc/src/sgml/ref/explain.sgml | 4 +++- src/backend/commands/explain.c | 14 +++++++++++++- src/backend/executor/instrument.c | 6 ++++++ src/include/executor/instrument.h | 2 ++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/doc/src/sgml/ref/explain.sgml b/doc/src/sgml/ref/explain.sgml index 6dda680aa0d..7a4eeb06b3e 100644 --- a/doc/src/sgml/ref/explain.sgml +++ b/doc/src/sgml/ref/explain.sgml @@ -241,7 +241,9 @@ ROLLBACK; Include information on WAL record generation. Specifically, include the number of records, number of full page images (fpi), the amount of WAL - generated in bytes and the number of times the WAL buffers became full. + generated in bytes, the number of times the WAL buffers became full, the + amount of WAL fpi generated in bytes after compression, and the amount of + WAL fpi generated in bytes before compression. In text format, only non-zero values are printed. This parameter may only be used when ANALYZE is also enabled. It defaults to FALSE. diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index e6edae0845c..4dcfaf08cca 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -4283,7 +4283,9 @@ show_wal_usage(ExplainState *es, const WalUsage *usage) { /* Show only positive counter values. */ if ((usage->wal_records > 0) || (usage->wal_fpi > 0) || - (usage->wal_bytes > 0) || (usage->wal_buffers_full > 0)) + (usage->wal_bytes > 0) || (usage->wal_buffers_full > 0) || + (usage->wal_fpi_bytes_uncompressed > 0) || + (usage->wal_fpi_bytes_compressed > 0)) { ExplainIndentText(es); appendStringInfoString(es->str, "WAL:"); @@ -4300,6 +4302,12 @@ show_wal_usage(ExplainState *es, const WalUsage *usage) if (usage->wal_buffers_full > 0) appendStringInfo(es->str, " buffers full=%" PRId64, usage->wal_buffers_full); + if (usage->wal_fpi_bytes_uncompressed > 0) + appendStringInfo(es->str, " fpi bytes uncompressed=%" PRIu64, + usage->wal_fpi_bytes_uncompressed); + if (usage->wal_fpi_bytes_compressed > 0) + appendStringInfo(es->str, " fpi bytes compressed=%" PRIu64, + usage->wal_fpi_bytes_compressed); appendStringInfoChar(es->str, '\n'); } } @@ -4313,6 +4321,10 @@ show_wal_usage(ExplainState *es, const WalUsage *usage) usage->wal_bytes, es); ExplainPropertyInteger("WAL Buffers Full", NULL, usage->wal_buffers_full, es); + ExplainPropertyUInteger("WAL FPI Bytes Uncompressed", NULL, + usage->wal_fpi_bytes_uncompressed, es); + ExplainPropertyUInteger("WAL FPI Bytes Compressed", NULL, + usage->wal_fpi_bytes_compressed, es); } } diff --git a/src/backend/executor/instrument.c b/src/backend/executor/instrument.c index 56e635f4700..1d11a001d22 100644 --- a/src/backend/executor/instrument.c +++ b/src/backend/executor/instrument.c @@ -281,6 +281,8 @@ WalUsageAdd(WalUsage *dst, WalUsage *add) dst->wal_records += add->wal_records; dst->wal_fpi += add->wal_fpi; dst->wal_buffers_full += add->wal_buffers_full; + dst->wal_fpi_bytes_uncompressed += add->wal_fpi_bytes_uncompressed; + dst->wal_fpi_bytes_compressed += add->wal_fpi_bytes_compressed; } void @@ -290,4 +292,8 @@ WalUsageAccumDiff(WalUsage *dst, const WalUsage *add, const WalUsage *sub) dst->wal_records += add->wal_records - sub->wal_records; dst->wal_fpi += add->wal_fpi - sub->wal_fpi; dst->wal_buffers_full += add->wal_buffers_full - sub->wal_buffers_full; + dst->wal_fpi_bytes_uncompressed += + add->wal_fpi_bytes_uncompressed - sub->wal_fpi_bytes_uncompressed; + dst->wal_fpi_bytes_compressed += + add->wal_fpi_bytes_compressed - sub->wal_fpi_bytes_compressed; } diff --git a/src/include/executor/instrument.h b/src/include/executor/instrument.h index 03653ab6c6c..2cc9c1e2b88 100644 --- a/src/include/executor/instrument.h +++ b/src/include/executor/instrument.h @@ -54,6 +54,8 @@ typedef struct WalUsage int64 wal_fpi; /* # of WAL full page images produced */ uint64 wal_bytes; /* size of WAL records produced */ int64 wal_buffers_full; /* # of times the WAL buffers became full */ + uint64 wal_fpi_bytes_uncompressed; /* size of FPIs before compression */ + uint64 wal_fpi_bytes_compressed; /* size of FPIs after compression */ } WalUsage; /* Flag bits included in InstrAlloc's instrument_options bitmask */ -- 2.47.3