PostgreSQL replication lag alert
Detect the moment a replica falls behind the primary by more than 10 seconds.
Recipe
sql
-- На standby-реплике; экспонировать как HTTP endpoint и мониторить
SELECT
CASE WHEN pg_is_in_recovery()
AND EXTRACT(EPOCH FROM (now() - pg_last_xact_replay_timestamp())) > 10
THEN 'lag'
ELSE 'ok'
END AS status;
Same thing in Enterno.io
Wrap the SQL as an HTTP endpoint (/replication-status → "ok"/"lag") and point an Enterno HTTP monitor at it with rule "not 200 or body ≠ ok".