ThingWorx 高可用性 > Pgpool-II を使用した PostgreSQL HA の展開例 > 6. ストリーミングレプリケーション用データベースの node2 としての設定
6. ストリーミングレプリケーション用データベースの node2 としての設定
フォルダ /db/node0archive/db/node1archive、および /db/node2archive が作成され、3 つのノード間で共有されていることを確認します。
ステップ 1
ユーザー replicator を作成します (node0 のときと同じ操作)。
ステップ 2
行 #10 以外は node0 の postgres.conf パラメータと同じものを使用するように node1 の postgres.conf を編集します。行 #10 は代わりに以下の値にします。
パラメータ
ノード
10
synchronous_standby_names
'node0,node1'
ステップ 3
node0 と同じ start_replication.sh スクリプトを node1 に作成します。
ステップ 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
pg_hba.conf を更新します (node0 のときと同じ操作)。