PostgreSQL 主从复制中断的定位与恢复
备库不再接收/回放 WAL,pg_stat_replication 在主机上为空,备库 pg_last_wal_receive_lsn 停止增长。日志出现 could not receive data from WAL stream 或 timeline 错误。
主机:
SELECT * FROM pg_stat_replication;
SELECT slot_name, active, restart_lsn FROM pg_replication_slots;
备库:
SELECT pg_last_wal_receive_lsn(), pg_last_wal_replay_lsn(),
now() - pg_last_xact_replay_timestamp();
SHOW primary_conninfo;
journalctl -u postgresql --since '30 min ago'
df -h
pg_hba.conf 变更。pg_rewind 或重新 pg_basebackup。primary_conninfo 和 timeline。合上页面,先回答,再展开对照。
pg_stat_replication(为空说明备库未连上)和 pg_replication_slots;备库看 pg_last_wal_receive_lsn()、pg_last_wal_replay_lsn() 是否停止增长,以及 now() - pg_last_xact_replay_timestamp() 和 SHOW primary_conninfo。pg_rewind 或重新执行 pg_basebackup 重建备库。primary_conninfo 和 timeline;网络/认证问题修好后重启备库的 WAL receiver。
小程序版
微信扫码,随时查命令