fix(monitoring): don't false-fire the WAL-stalled alert on an idle database #241
Reference in New Issue
Block a user
Delete Branch "fix/pg-archive-stalled-idle-falsepositive"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
A
WAL archiving stalledcritical alert fired on prod during a quiet period. Investigatedon the host — it was a false positive:
pg_wal64 MB and not growing;pg_stat_archiver.failed_count = 0, zero.readysegments — archiving is not failing;pg_current_wal_insert_lsn()frozen across samples, current segment essentially empty — theDB had simply had no writes for ~2.5 h;
pgbackrest --stanza=scrabble --pg1-user=scrabble checksucceeded end-to-end (segment archivedto S3), and daily backups are current.
Root cause: an idle Postgres archives nothing — it never force-switches an empty WAL segment on
archive_timeout— sopg_stat_archiver_last_archive_ageclimbs past 30 min even thougharchiving is perfectly healthy. The rule watched only that age, so it false-fires every quiet
hour. Nothing was at risk (no writes ⇒ the "frozen" recovery point equals the live state).
What
pg_archive_stallednow fires only when the age is high and pg_wal is actually growing(WAL produced but not archived — the real "pg_wal fills the disk" danger):
(pg_stat_archiver_last_archive_age > 1800) and on() (delta(pg_wal_size_bytes[35m]) > 16MB).Genuine
archive_commandfailures stay covered bypg_archive_failing(
increase(failed_count[15m]) > 0), untouched.and on()bridges the two metrics' differinglabel sets;
delta()suits thepg_wal_size_bytesgauge (pg_stat_walis not exported here).Validated on prod with
promtool— the expression is empty while idle.pgbackrest checkneeds--pg1-user=scrabble,or it connects as role
root(absent) and aborts with "no database found".Deploy note
This is prod-only monitoring (PITR runs on prod, not the test contour). To take effect on prod
the Grafana provisioning must be re-read (recreate the
scrabble-grafanacontainer after the filelands on the host). It rides a prod deploy, or I can apply it targeted (a
--force-recreate grafana) once merged — your call. Not urgent: the alert already self-cleared (thepgbackrest checkadvanced the recovery point), and the false positive is benign.No app code touched.