Use the following query at the source cluster to check status and lag (lag is in bytes):
select application_name, pid, client_addr, state, sync_state,
pg_wal_lsn_diff(sent_lsn, write_lsn) as write_lag,
pg_wal_lsn_diff(sent_lsn, flush_lsn) as flush_lag,
pg_wal_lsn_diff(sent_lsn, replay_lsn) as replay_lag
from pg_stat_replication;
To get replication lag by duration (postgres duration):
select application_name, pid, client_addr, state, sync_state, write_lag, flush_lag, replay_lag from pg_stat_replication;
column | lag type |
---|---|
write_lag | Data not yet received by client |
flush_lag | Data received by client, but not yet flushed to disk (durable) |
replay_lag | Data flushed to disk at client, but not yet replayed (available for read) |
A missing PID means replication has broken somehow.