修复分叉的 PostgreSQL 备库
pg_rewind 在旧主库重新加入集群时,把它与当前主库的差异块同步过来,避免全量重做基础备份。它适合时间线分叉后的备库回退。
pg_rewind --target-pgdata=/var/lib/pgsql/data \
--source-server="host=primary port=5432 user=repl dbname=postgres"
pg_rewind --target-pgdata=/var/lib/pgsql/data \
--source-server="host=primary port=5432 user=repl" --dry-run
pg_rewind --target-pgdata=/var/lib/pgsql/data \
--source-server="..." --progress
pg_rewind --target-pgdata=/var/lib/pgsql/data \
--source-pgdata=/backup/base
wal_log_hints 或数据校验和;否则可能无法完成。primary_conninfo 并启动。--dry-run 只检查,不写数据;正式执行前先跑。pg_basebackup — 重建备库pg_waldump — 分析 WALpg_ctl — 启动备库