I have a PostgreSQL cluster with following databases with user myuser
:
I have set up a replication with one master (192.168.50.8) and one slave (192.168.50.9). I failover to the slave, and when I try to failback to the original master using pg_rewind
for every database, pg_rewind
succeeds for the first database but fails for the second database.
For database1, running the following command on(192.168.50.8) works:
/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"
For database2, running the following command on (192.168.50.8) gives me an error:
/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"
Error:
target server must be shut down cleanly
failure, exiting
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.