天天看點

Postgresql - 檢查資料庫主從複制進度

如何檢視主從複制的狀态,且備庫應用落後了多少位元組

這些資訊要在主庫中查詢

檢視流複制的資訊可以使用主庫上的視圖 select pid,state,client_addr,sync_priority,sync_state from pg_stat_replication;

pg_stat_replication中幾個字斷記錄了發送wal的位置及備庫接收到的wal的位置、 sent_location--發送wal的位置 write_location--備庫接收到的wal的位置 flush_location—備庫寫wal日志到磁盤的位置 replay_location—備庫應用日志的位置

檢視備庫落後主庫多少位元組 select pg_xlog_location_diff(pg_current_xlog_location(),replay_location)/1024/1024 as MB from pg_stat_replication; select pg_xlog_location_diff(pg_current_xlog_location(),replay_location)/1024/1024/1024 as GB from pg_stat_replication;

級聯複制 select pg_xlog_location_diff(pg_last_xlog_replay_location(),replay_location)/1024/1024/1024 as GB from pg_stat_replication;