PostgreSQL replication lag alert
Detect the moment a replica falls behind the primary by more than 10 seconds.
Recipe
-- На 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".
Related recipes
Redis slave is behind master — read-after-write returns stale data. No native alert, you need an external one.
A replica-set secondary falls behind the primary; the app will read stale data within a minute. Want an HTTP endpoint that says "ok" or "lag".
Every week some analyst fires off a heavy SELECT without LIMIT and blocks other transactions. You want to know within a minute, not within an hour.