6. 将用于流式复制的数据库配置为 node2
确保已创建 /db/node0archive、/db/node1archive 和 /db/node2archive 文件夹,并在三个节点之间进行了共享。
步骤 1
步骤 2
行
|
参数
|
值
|
节点
|
10
|
synchronous_standby_names
|
'node0,node1'
|
|
步骤 3
步骤 4
重新定位 node2 的 Master.sh 脚本。
创建脚本 retargetMaster.sh:
vim /db/bin/retargetMaster.sh
其中包含以下内容 (与 node0 版本稍有不同):
#!/bin/bash -x
NEW_MASTER_HOSTNAME=$1
NEW_ARCHIVE_FOLDER=$2
if grep -q "$1" /db/postgres/recovery.conf
then
echo $1 is current target,server does not need a restart, done!
else
#service postgresql stop
/usr/pgsql-10.x/bin/pg_ctl -D /db/postgres stop -m fast
#/db/bin/start_replication.sh $NEW_MASTER_HOSTNAME
# Write out new recovery.conf file
rm /db/postgres/recovery.conf
echo "standby_mode = 'on'" >> /db/postgres/recovery.conf
echo "primary_conninfo = 'port=5432 host=$NEW_MASTER_HOSTNAME user=replicator password=trUf6yuz2?_Gub sslmode=disable sslcompression=1 application_name=node1'" >> /db/postgres/recovery.conf
echo "trigger_file='/db/trigger'" >> /db/postgres/recovery.conf
echo "restore_command = 'cp -f $NEW_ARCHIVE_FOLDER/%f %p>/db/postgres/recovery.conf
echo "archive_cleanup_command = '/usr/bin/pg_archivecleanup $NEW_ARCHIVE_FOLDER %r>/db/postgres/recovery.conf
echo "recovery_target_timeline = 'latest'" >> /db/postgres/recovery.conf
/usr/pgsql-10.x/bin/pg_ctl -D /db/postgres -l /db/postgres.log start
echo target is $1 now
fi
然后,将这些脚本设置为可执行脚本:
chmod a+x /db/bin/start_replication.sh
chmod a+x /db/bin/reargetMaster.sh
步骤 5