ThingWorx High Availability > Example Deployment of PostgreSQL HA with Pgpool-II > 6. Configure database for streaming replication as node2
6. Configure database for streaming replication as node2
Ensure folders /db/node0archive, /db/node1archive, and /db/node2archive has been created and shared across three nodes.
Step 1
Create user replicator (same actions as for node0).
Step 2
Edit postgres.conf on node1 to use the same postgres.conf parameters for node0, except for row #10, which should instead have the following value:
Row
Parameter
Value
Node
10
synchronous_standby_names
'node0,node1'
Step 3
node1 should have the same start_replication.sh script as node0.
Step 4
Retarget the Master.sh script for node2.
Create script retargetMaster.sh:
vim /db/bin/retargetMaster.sh
with following content (which is slightly different from the node0 version):
#!/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
Then, make the scripts executable:
chmod a+x /db/bin/start_replication.sh
chmod a+x /db/bin/reargetMaster.sh
Step 5
Update pg_hba.conf (same actions as for node0).
Was this helpful?