DBAtlas · 데이터베이스 운영 아틀라스

logical replication 모니터링(pg_stat_subscription, apply 오류, slot 지연)

PostgreSQL논리 복제

명령어

-- Subscriber:
SELECT subname, pid, leader_pid, relid::regclass AS syncing_table, received_lsn, latest_end_lsn, now() - last_msg_receipt_time AS since_last_msg, latest_end_time FROM pg_stat_subscription;
SELECT subname, apply_error_count, sync_error_count, stats_reset FROM pg_stat_subscription_stats;
-- Publisher:
SELECT slot_name, plugin, database, active, wal_status,
       pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), confirmed_flush_lsn)) AS confirmed_lag,
       pg_size_pretty(pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn)) AS retained_wal
FROM pg_replication_slots WHERE slot_type = 'logical';

하는 일

subscriber에서는 apply/tablesync worker, 수신 및 확인된 LSN, 마지막 메시지 시각, 누적 apply/sync 오류 수를 보여 준다. publisher에서는 logical slot의 미확인(confirmed_flush) WAL과 보존 중인 전체 WAL을 보여 준다.

사용 시점

logical replication 구성 중, 업그레이드/마이그레이션 전환 시 지연이 0에 가까워지는지 확인하기 위해, 오류 알림용.

주의

pid가 NULL이면 apply worker가 실행 중이 아니다(subscription 비활성화 또는 반복 실패 후 재시작). 서버 로그를 확인한다. apply_error_count가 증가하면 충돌이 있다는 뜻이다. 멈춘 subscription은 publisher에 WAL과 catalog_xmin을 쌓으므로 publisher 디스크와 카탈로그 bloat을 모니터링한다.

DBAtlas에서 열기 →

관련 항목