接上回,備機在檢測到主機掛掉后,備機通過standby promote成功升級為主機繼續提供服務
此時集群狀態如下:
接下來需要恢復原主機為備機加入集群繼續提供服務
1、主機執行node rejoin,將節點重新加入集群:
./repmgr node rejoin -h192.168.101.7 -Upostgres -dpostgres
[postgres@localhost bin]$ ./repmgr node rejoin -h192.168.101.7 -Upostgres -dpostgres ERROR: this node cannot attach to rejoin target node 2 DETAIL: rejoin target server's timeline 2 forked off current database system timeline 1 before current recovery point 0/8000028 HINT: use --force-rewind to execute pg_rewind
報錯日志可以看出,此時的節點和現在的主節點日志發生了分歧,需要調用--force-rewind重做備機,執行如下命令即可
./repmgr node rejoin -h192.168.101.7 -Upostgres -dpostgres --force-rewind
檢查節點狀態,可知原主機成功作為備機加入集群提供服務
./repmgr cluster show
ps:調用pg_rewind重做備機有丟失原主機數據風險,需要注意。