Skip to content

PopSQL: limited support.

Migrate now →

Replication lag

For a primary with replicas: how far behind each one is, in bytes and in time. Empty on a server with no replicas.

PostgreSQL · SQL
SELECT client_addr,
       application_name,
       state,
       sync_state,
       pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn) AS replay_lag_bytes,
       EXTRACT(EPOCH FROM replay_lag)::numeric(10,2) AS replay_lag_seconds
FROM pg_stat_replication
ORDER BY replay_lag_bytes DESC

This query is part of the "PostgreSQL health" pack: connect the database in DataRunner and install the whole pack — queries, dashboard and checks — at once.