主从切换
1. 停止主节点
$ pg_ctl stop
waiting for server to shut down.... done
server stopped
2. 从节点提升为主节点
$ pg_ctl promote
waiting for server to promote.... done
server promoted
验证是否切换成功
$ psql -h 127.0.0.1 -p 5432 -U postgres -W -c "select pg_is_in_recovery();"
Password:
pg_is_in_recovery
-------------------
f
当输出值为
f
则说明该节点为主节点