PostgreSQL monitoring
Monitor standby catch-up separately from replication connection health for PostgreSQL physical streaming replication.
Last updated
On this page (5)
PostgreSQL ยท Monitoring
Before you start
- A primary with a physical standby and approved statistics access, such as a monitoring role with pg_read_all_stats.
- A replication lag budget and a way to generate a harmless test write.
Procedure
- Collect pg_stat_replication on the primary and track expected standby connections, state and replay_lsn. A missing standby row is an alert condition, not zero lag.
- Use pg_wal_lsn_diff with pg_current_wal_lsn() and replay_lsn to measure WAL bytes awaiting replay. Compare trends to write volume; replay_lag is not a forecast of catch-up time and may be NULL on an idle system.
- Alert on sustained excess backlog and missing standby independently. Record the affected replication client in the notification.
Verify the result
- An approved test write advances the replay position and becomes visible on the standby if read access is enabled.
- A staging interruption alerts when the standby disappears or falls behind, and recovery clears the alert without misclassifying idle time as lag.
