복제 지연 조회
PostgreSQL복제명령어
SELECT client_addr, state, sent_lsn, replay_lsn, pg_wal_lsn_diff(pg_current_wal_lsn(), replay_lsn) AS replay_lag_bytes, write_lag, flush_lag, replay_lag FROM pg_stat_replication;하는 일
primary에서 각 standby의 replay 차이를 primary의 현재 WAL 위치 대비 바이트 단위로, write/flush/replay lag와 함께 보여 준다.
사용 시점
streaming replication이 얼마나 뒤처졌는지 모니터링하기 위해(primary에서 실행).
주의
standby에서 초 단위 지연: SELECT now() - pg_last_xact_replay_timestamp(); 이 값은 primary에 쓰기가 없을 때도 증가하므로 LSN 차이와 함께 해석한다. 결과가 비어 있으면 연결된 standby가 없는 것이다.