Postgres Replication Lag Cheat Sheet

Detect, alert, and failover

Last Updated: November 21, 2025

Focus Areas

Focus
Track replication slots
Promote replicas when lag spiking

Commands & Queries

SELECT * FROM pg_stat_replication
Inspect lag
pg_ctl promote -D /var/lib/pgsql/data
Promote replica
pg_receivewal
Stream WAL for DR

Summary

Low lag ensures standby nodes stay ready for failover.

💡 Pro Tip: Alert on `write_lag` thresholds and plan manual failovers ahead of time.
← Back to Databases & APIs | Browse all categories | View all cheat sheets