From 72bb6a453e7e20239e0a900aeb555d9ab745d43e Mon Sep 17 00:00:00 2001 From: Ashutosh Bapat Date: Thu, 25 Sep 2025 10:15:43 +0530 Subject: [PATCH 2/2] Address review comments from Bertrand When the stats are not enabled, we should reset the plugin stats to 0, rather than carrying over the stale stats from the time when the plugin was supporting the stats. This does not matter if the plugin continues not to support statistics forever. But in case it was supporting the stats once, discontinued doing so at some point in time and then starts supporting the stats later, accumulating the new stats based on the earlier accumulated stats could be misleading. Also add a note in the documentation mentioning that stats, once supported should remain supported. Author: Ashutosh Bapat --- doc/src/sgml/logicaldecoding.sgml | 8 ++++++++ doc/src/sgml/monitoring.sgml | 10 +++++----- src/backend/utils/activity/pgstat_replslot.c | 8 ++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/doc/src/sgml/logicaldecoding.sgml b/doc/src/sgml/logicaldecoding.sgml index c02d4a88d57..0bf9ffbfd28 100644 --- a/doc/src/sgml/logicaldecoding.sgml +++ b/doc/src/sgml/logicaldecoding.sgml @@ -966,6 +966,14 @@ typedef struct OutputPluginStats ReorderBufferChangeSize may be used to find the size of filtered ReorderBufferChange. + + + + Once a plugin starts reporting and maintaining these statistics, it is + not expected that they will discontinue doing so. If they do, the result + may be misleading because of the cumulative nature of these statistics. + + diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index fbe03ffd670..4d414d71742 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -1663,7 +1663,7 @@ description | Waiting for a newly initialized WAL file to reach durable storage Amount of changes, from total_wal_bytes, filtered out by the output plugin and not sent downstream. Please note that it does not include the changes filtered before a change is sent to - the output plugin, e.g. the changes filtered by origin. The count is + the output plugin, e.g. the changes filtered by origin. The counter is maintained by the output plugin mentioned in plugin. It is NULL when statistics is not initialized or immediately after a reset or when not maintained by the @@ -1678,9 +1678,9 @@ description | Waiting for a newly initialized WAL file to reach durable storage Number of decoded transactions sent downstream for this slot. This counts top-level transactions only, and is not incremented for - subtransactions. These transactions are subset of transctions sent to - the decoding plugin. Hence this count is expected to be lesser than or - equal to total_wal_txns. The count is maintained + subtransactions. These transactions are subset of transactions sent to + the decoding plugin. Hence this count is expected to be less than or + equal to total_wal_txns. The counter is maintained by the output plugin mentioned in plugin. It is NULL when statistics is not initialized or immediately after a reset or when not maintained by the output plugin. @@ -1694,7 +1694,7 @@ description | Waiting for a newly initialized WAL file to reach durable storage Amount of transaction changes sent downstream for this slot by the output plugin after applying filtering and converting into its output - format. The count is maintained by the output plugin mentioned in + format. The counter is maintained by the output plugin mentioned in plugin. It is NULL when statistics is not initialized or immediately after a reset or when not maintained by the output plugin. diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c index 895940f4eb9..c3a2fe3d3f9 100644 --- a/src/backend/utils/activity/pgstat_replslot.c +++ b/src/backend/utils/activity/pgstat_replslot.c @@ -88,6 +88,7 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re /* Update the replication slot statistics */ #define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld +#define REPLSLOT_SET_TO_ZERO(fld) statent->fld = 0 REPLSLOT_ACC(spill_txns); REPLSLOT_ACC(spill_count); REPLSLOT_ACC(spill_bytes); @@ -103,7 +104,14 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re REPLSLOT_ACC(plugin_sent_bytes); REPLSLOT_ACC(plugin_filtered_bytes); } + else + { + REPLSLOT_SET_TO_ZERO(plugin_sent_txns); + REPLSLOT_SET_TO_ZERO(plugin_sent_bytes); + REPLSLOT_SET_TO_ZERO(plugin_filtered_bytes); + } #undef REPLSLOT_ACC +#undef REPLSLOT_SET_TO_ZERO pgstat_unlock_entry(entry_ref); } -- 2.34.1