我有一个PostgreSQL集群,其中的以下数据库具有用户myuser
:
我设置了一个主服务器(192.168.50.8)和一个从服务器(192.168.50.9)的复制。我故障转移到从属服务器,并且当我尝试对每个数据库使用pg_rewind
故障恢复到原始主机时,pg_rewind
对于第一个数据库成功,但对第二个数据库失败。
对于database1,可以在(192.168.50.8)上运行以下命令:
/usr/pgsql-11/bin/pg_rewind -D "data_dir_path_here" --source-server="port=pg_port_here user=myuser dbname=database1 host=192.168.50.9"
对于database2,在(192.168.50.8)上运行以下命令会给我一个错误:
/usr/pgsql-11/bin/pg_rewind -D "data_dir_path_here" --source-server="port=pg_port_here user=myuser dbname=database2 host=192.168.50.9"
错误:
target server must be shut down cleanly
failure, exiting
答案 0 :(得分:1)
You use pg_rewind
with the old master (192.168.50.8) to turn it into a slave. If the shutdown wan't clean, you have to run crash recovery on PostgreSQL (just start the server and stop it again as soon as crash recovery is done). Then you can run pg_rewind
.
pg_rewind
affects the whole database cluster, so you do not run it for each database. You run it once on the old master that is supposed to become the new slave.
If you use the --source-server
option of pg_rewind
to connect to the new master, it doesn't matter which database you specify. Any database will do, and the effect will be the same.