diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c index 895940f4eb9..e4dbbf4f405 100644 --- a/src/backend/utils/activity/pgstat_replslot.c +++ b/src/backend/utils/activity/pgstat_replslot.c @@ -80,12 +80,17 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re PgStat_EntryRef *entry_ref; PgStatShared_ReplSlot *shstatent; PgStat_StatReplSlotEntry *statent; + bool previous_had_stats; + bool current_has_stats; entry_ref = pgstat_get_entry_ref_locked(PGSTAT_KIND_REPLSLOT, InvalidOid, ReplicationSlotIndex(slot), false); shstatent = (PgStatShared_ReplSlot *) entry_ref->shared_stats; statent = &shstatent->stats; + previous_had_stats = statent->plugin_has_stats; + current_has_stats = repSlotStat->plugin_has_stats; + /* Update the replication slot statistics */ #define REPLSLOT_ACC(fld) statent->fld += repSlotStat->fld REPLSLOT_ACC(spill_txns); @@ -97,7 +102,15 @@ pgstat_report_replslot(ReplicationSlot *slot, const PgStat_StatReplSlotEntry *re REPLSLOT_ACC(total_wal_txns); REPLSLOT_ACC(total_wal_bytes); statent->plugin_has_stats = repSlotStat->plugin_has_stats; - if (repSlotStat->plugin_has_stats) + + /* Plugin no longer supports stats, reset counters */ + if (previous_had_stats && !current_has_stats) { + statent->plugin_sent_txns = 0; + statent->plugin_sent_bytes = 0; + statent->plugin_filtered_bytes = 0; + } + + if (current_has_stats) { REPLSLOT_ACC(plugin_sent_txns); REPLSLOT_ACC(plugin_sent_bytes);