Skip to content

Commit e2d6bd0

Browse files
authored
fix(metrics): skip pg_stat_archiver metrics on non-archiving standbys (#9411)
After a PostgreSQL instance is demoted from primary to standby, the `pg_stat_archiver` view retains stale data from when the instance was archiving WAL files. This causes misleading metrics and false alerts (e.g., "last archive age > 7 minutes") on standby nodes that do not actively archive WAL. This fix adds a predicate_query to the `pg_stat_archiver` metrics collection that only runs the query on instances that actually perform WAL archiving: - Primary instances (not in recovery) - Designated primary replicas (archive_mode='always' in replica clusters) Regular standby nodes will no longer export `pg_stat_archiver` metrics, preventing stale data from triggering false alerts. Fixes #9101 Signed-off-by: Armando Ruocco <[email protected]>
1 parent 53cb703 commit e2d6bd0

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎config/manager/default-monitoring.yaml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ data:
173173
, COALESCE(CAST(CAST('x'||pg_catalog.right(pg_catalog.split_part(last_failed_wal, '.', 1), 16) AS pg_catalog.bit(64)) AS pg_catalog.int8), -1) AS last_failed_wal_start_lsn
174174
, EXTRACT(EPOCH FROM stats_reset) AS stats_reset_time
175175
FROM pg_catalog.pg_stat_archiver
176+
predicate_query: |
177+
SELECT NOT pg_catalog.pg_is_in_recovery()
178+
OR pg_catalog.current_setting('archive_mode') = 'always'
176179
metrics:
177180
- archived_count:
178181
usage: "COUNTER"

0 commit comments

Comments
 (0)