Configure REPMGR (replica node – DR)
This needs to be carried out on the secondary (replica) node on the DR database. Note that the commands executed here are different in the secondary node.
-
Configure the REPMGR configuration file (default located on
“/etc/repmgr/10/repmgr.conf”) by changing the configuration as
follows:
node_id = 3 node_name = ‘DR’ conninfo = 'host=<local-ip> port=5432 user=repuser dbname=postgres password=<postgres user password>' replication_type = 'physical' use_replication_slots = yes pg_bindir = '/usr/pgsql-10/bin'. failover = 'automatic' priority=0 data_directory = '/var/lib/pgsql/10/data' promote_command = '/usr/pgsql-10/bin/repmgr standby promote -f /etc/repmgr/10/repmgr.conf --log-to-file' follow_command = '/usr/pgsql-10/bin/repmgr standby follow -f /etc/repmgr/10/repmgr.conf --log-to-file --upstream-node-id=%n' monitoring_history = yes monitor_interval_secs = 10 service_start_command = 'sudo systemctl start postgresql-10' service_stop_command = 'sudo systemctl stop postgresql-10' service_restart_command = 'sudo systemctl restart postgresql-10' service_reload_command = 'sudo systemctl reload postgresql-10'
- After changing the above configurations, the postgres linux user needs to initialize the replica node. (except for the systemctl commands)
-
Shut down PostgreSQL (root) by entering the following command:
systemctl stop postgresql-10
-
Delete the data directory (as it will be cloned later on):
-
cd /var/lib/pgsql/10/data
-
rm -rdf *
-
-
Clone the data from the primary (postgres user):
-
su - postgres
-
PGPASSWORD=<place postgres user password> /usr/pgsql-10/bin/repmgr -f /etc/repmgr/10/repmgr.conf -h <primary-ip> -U repuser -d postgres standby clone
-
exit
-
-
Start PostgreSQL (root):
systemctl start postgresql-10
-
Register the standby (postgres user):
-
su - postgres
-
/usr/pgsql-10/bin/repmgr -f /etc/repmgr/10/repmgr.conf standby register
-
exit
-
-
Make sure that the secondary was registered by running the following
command:
-
su - postgres
-
/usr/pgsql-10/bin/repmgr -f /etc/repmgr/10/repmgr.conf cluster show
-
exit
-
-
Start repmgr10 Service (root) – on all nodes!
-
systemctl enable repmgr10
-
systemctl start repmgr10
-
Validate the service is running by entering
systemctl status repmgr10
-