-- pgMonitor Exporter (ccp_replication_lag_size)SELECT client_addr as replica, client_hostname as replica_hostname, client_port as replica_port, pg_wal_lsn_diff(sent_lsn, replay_lsn) as bytesFROM pg_catalog.pg_stat_replication
Replication Lag (in seconds)
-- pgMonitor Exporter (ccp_replication_lag)SELECT CASE WHEN pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn() THEN 0 ELSE EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())::INTEGER END AS replay_time, EXTRACT (EPOCH FROM now() - pg_last_xact_replay_timestamp())::INTEGER AS received_time
-- pgMonitor Exporter (ccp_replication_slots)SELECT slot_name, active::int, pg_wal_lsn_diff(pg_current_wal_insert_lsn(), restart_lsn) AS retained_bytes FROM pg_catalog.pg_replication_slots;
Gap between pg_current_wal_lsn and sent_lsn may indicate heavy load on source system. Gap between sent_lsn and pg_last_wal_receive_lsn on standby may indicate network delay or standby under heavy load.