Postgres Master Slave setup
bash-4.2$ pwd
/database/edb/as14
bash-4.2$ cat postgresql.conf | grep 'max_wal_senders\|max_replication_slots\|wal_level\|hot_standby\|archive_mode\|archive_command\|shared_preload_libraries'
wal_level = replica # minimal, replica, or logical
archive_mode = on # enables archiving; off, on, or always
archive_command = '/bin/true'
#archive_command = 'test ! -f barman@postonline:/var/lib/barman/dev-pgsql/incoming/%f && rsync -a %p barman@postonline:/var/lib/barman/dev-pgsql/incoming/%f' # command to use to archive a logfile segment
max_wal_senders = 10 # max number of walsender processes
max_replication_slots = 10 # max number of replication slots
hot_standby = on # "off" disallows queries during recovery
#hot_standby_feedback = off # send info from standby to prevent
shared_preload_libraries = '$libdir/dbms_pipe,$libdir/edb_gen,$libdir/dbms_aq,repmgr'
bash-4.2$
bash-4.2$ /usr/edb/as14/bin/psql -d postgres -U enterprisedb
psql (14.11.0)
Type "help" for help.
postgres=# create user repmgr;
CREATE ROLE
postgres=# create database repmgr with owner repmgr;
CREATE DATABASE
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU | Access privileges
-----------+--------------+----------+-------------+-------------+-----+-------------------------------
dev | test | UTF8 | C | C | |
edb | enterprisedb | UTF8 | C | C | |
postgres | enterprisedb | UTF8 | C | C | |
repmgr | repmgr | UTF8 | C | C | |
sit | test | UTF8 | en_US.UTF-8 | en_US.UTF-8 | |
template0 | enterprisedb | UTF8 | C | C | | =c/enterprisedb +
| | | | | | enterprisedb=CTc/enterprisedb
template1 | enterprisedb | UTF8 | C | C | | =c/enterprisedb +
| | | | | | enterprisedb=CTc/enterprisedb
(7 rows)
postgres=#
bash-4.2$ /usr/edb/as14/bin/repmgr
ERROR: following errors were found in the configuration file:
"node_id": required parameter was not found
"node_name": required parameter was not found
"data_directory": required parameter was not found
"conninfo": required parameter was not found
DETAIL: configuration file is: "/etc/repmgr/14/repmgr.conf"
bash-4.2$
cat /etc/repmgr/14/repmgr.conf | grep "node_id\|node_name\|conninfo\|data_directory\|failover\|promote_command\|follow_command"
[root@postoffline ~]# cat /etc/repmgr/14/repmgr.conf | grep "node_id\|node_name\|conninfo\|data_directory\|failover\|promote_command\|follow_command"
node_id=1 # A unique integer greater than zero
node_name='postoffline' # An arbitrary (but unique) string; we recommend
conninfo='host=postoffline user=repmgr dbname=repmgr connect_timeout=2' # Database connection information as a conninfo string.
# For details on conninfo strings, see:
# "connect_timeout" in the conninfo string to determine
data_directory='/database/edb/as14' # The node's data directory. This is needed by repmgr
# defaults to the user defined in "conninfo".
# is used during failover to check visibility of the
#use_primary_conninfo_password=false # explicitly set "password" in "primary_conninfo"
#passfile='' # path to .pgpass file to include in "primary_conninfo"
failover='automatic' # one of 'automatic', 'manual'.
promote_command='/usr/edb/as14/bin/repmgr standby promote -f /etc/repmgr/14/repmgr.conf --log-to-file' # command repmgrd executes when promoting a new primary; use something like:
follow_command='/usr/edb/as14/bin/repmgr standby follow -f /etc/repmgr/14/repmgr.conf --log-to-file --upstream-node-id=%n' # command repmgrd executes when instructing a standby to follow a new primary;
# executing "follow_command" (defaults to the value set in "standby_reconnect_timeout")
#standby_disconnect_on_failover=false # If "true", in a failover situation wait for all standbys to
#sibling_nodes_disconnect_timeout=30 # If "standby_disconnect_on_failover" is true, the maximum length of time
#primary_visibility_consensus=false # If "true", only continue with failover if no standbys have seen
#failover_validation_command='' # Script to execute for an external mechanism to validate the failover
# value: %n (node_id), %a (node_name). *Must* be the same on all nodes.
#election_rerun_interval=15 # if "failover_validation_command" is set, and the command returns
#service_promote_command = '' # This parameter is intended for systems which provide a
# for "promote_command"; do not use "repmgr standby promote"
[root@postoffline ~]#
bash-4.2$ cat pg_hba.conf | grep repmgr
host repmgr repmgr 192.168.0.110/32 md5
bash-4.2$
/usr/edb/as14/bin/repmgr -f /etc/repmgr/14/repmgr.conf primary register
bash-4.2$ /usr/edb/as14/bin/repmgr -f /etc/repmgr/14/repmgr.conf primary register
INFO: connecting to primary database...
NOTICE: attempting to install extension "repmgr"
ERROR: "repmgr" is not a superuser and no superuser name supplied
HINT: supply a valid superuser name with -S/--superuser
bash-4.2$
ALTER USER repmgr WITH SUPERUSER;
bash-4.2$ /usr/edb/as14/bin/psql -d postgres -U enterprisedb
psql (14.11.0)
Type "help" for help.
postgres=# ALTER USER repmgr WITH SUPERUSER;
ALTER ROLE
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU | Access privileges
-----------+--------------+----------+-------------+-------------+-----+-------------------------------
dev | test | UTF8 | C | C | |
edb | enterprisedb | UTF8 | C | C | |
postgres | enterprisedb | UTF8 | C | C | |
repmgr | repmgr | UTF8 | C | C | |
sit | test | UTF8 | en_US.UTF-8 | en_US.UTF-8 | |
template0 | enterprisedb | UTF8 | C | C | | =c/enterprisedb +
| | | | | | enterprisedb=CTc/enterprisedb
template1 | enterprisedb | UTF8 | C | C | | =c/enterprisedb +
| | | | | | enterprisedb=CTc/enterprisedb
(7 rows)
postgres=# \du
List of roles
Role name | Attributes | Member of
-----------------------+------------------------------------------------------------+-----------
aq_administrator_role | No inheritance, Cannot login +| {}
| Profile default |
barman | Superuser +| {}
| Profile default |
enterprisedb | Superuser, Create role, Create DB, Replication, Bypass RLS+| {}
| Profile default |
repmgr | Superuser +| {}
| Profile default |
test | Superuser +| {}
| Profile default |
postgres=#
/usr/edb/as14/bin/repmgr -f /etc/repmgr/14/repmgr.conf primary register
bash-4.2$ /usr/edb/as14/bin/repmgr -f /etc/repmgr/14/repmgr.conf primary register
INFO: connecting to primary database...
NOTICE: attempting to install extension "repmgr"
NOTICE: "repmgr" extension successfully installed
NOTICE: primary node record (ID: 1) registered
bash-4.2$
/usr/edb/as14/bin/repmgr -f /etc/repmgr/14/repmgr.conf cluster show
bash-4.2$ /usr/edb/as14/bin/repmgr -f /etc/repmgr/14/repmgr.conf cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string
----+-------------+---------+-----------+----------+----------+----------+----------+--------------------------------------------------------------
1 | postoffline | primary | * running | | default | 100 | 1 | host=postoffline user=repmgr dbname=repmgr connect_timeout=2
bash-4.2$
STANDBY - postonline
bash-4.2$ cd /usr/edb/as14/bin
bash-4.2$ ./repmgr
ERROR: following errors were found in the configuration file:
"node_id": required parameter was not found
"node_name": required parameter was not found
"data_directory": required parameter was not found
"conninfo": required parameter was not found
DETAIL: configuration file is: "/etc/repmgr/14/repmgr.conf"
bash-4.2$
[root@postonline ~]# cat /etc/repmgr/14/repmgr.conf | grep "node_id\|node_name\|conninfo\|data_directory\|failover\|promote_command\|follow_command"
node_id=2 # A unique integer greater than zero
node_name='postonline' # An arbitrary (but unique) string; we recommend
conninfo='host=postonline user=repmgr dbname=repmgr connect_timeout=2' # Database connection information as a conninfo string.
# For details on conninfo strings, see:
# "connect_timeout" in the conninfo string to determine
data_directory='/database/edb/as14' # The node's data directory. This is needed by repmgr
# defaults to the user defined in "conninfo".
# is used during failover to check visibility of the
#use_primary_conninfo_password=false # explicitly set "password" in "primary_conninfo"
#passfile='' # path to .pgpass file to include in "primary_conninfo"
failover='automatic' # one of 'automatic', 'manual'.
promote_command='/usr/edb/as14/bin/repmgr standby promote -f /etc/repmgr/14/repmgr.conf --log-to-file' # command repmgrd executes when promoting a new primary; use something like:
follow_command='/usr/edb/as14/bin/repmgr standby follow -f /etc/repmgr/14/repmgr.conf --log-to-file --upstream-node-id=%n' # command repmgrd executes when instructing a standby to follow a new primary;
# executing "follow_command" (defaults to the value set in "standby_reconnect_timeout")
#standby_disconnect_on_failover=false # If "true", in a failover situation wait for all standbys to
#sibling_nodes_disconnect_timeout=30 # If "standby_disconnect_on_failover" is true, the maximum length of time
#primary_visibility_consensus=false # If "true", only continue with failover if no standbys have seen
#failover_validation_command='' # Script to execute for an external mechanism to validate the failover
# value: %n (node_id), %a (node_name). *Must* be the same on all nodes.
#election_rerun_interval=15 # if "failover_validation_command" is set, and the command returns
#service_promote_command = '' # This parameter is intended for systems which provide a
# for "promote_command"; do not use "repmgr standby promote"
[root@postonline ~]#
[root@postoffline ~]# firewall-cmd --list-services
dhcpv6-client postgresql ssh
[root@postoffline ~]# firewall-cmd --add-port=5444/tcp
success
[root@postoffline ~]#
/usr/edb/as14/bin/repmgr -h postoffline -U repmgr -d repmgr -f /etc/repmgr/14/repmgr.conf standby clone --dry-run
bash-4.2$ /usr/edb/as14/bin/repmgr -h postoffline -U repmgr -d repmgr -f /etc/repmgr/14/repmgr.conf standby clone --dry-run
NOTICE: destination directory "/database/edb/as14" provided
INFO: connecting to source node
DETAIL: connection string is: host=postoffline user=repmgr dbname=repmgr
DETAIL: current installation size is 102 MB
INFO: "repmgr" extension is installed in database "repmgr"
INFO: replication slot usage not requested; no replication slot will be set up for this standby
INFO: parameter "max_wal_senders" set to 10
NOTICE: checking for available walsenders on the source node (2 required)
INFO: sufficient walsenders available on the source node
DETAIL: 2 required, 10 available
NOTICE: checking replication connections can be made to the source server (2 required)
INFO: required number of replication connections could be made to the source server
DETAIL: 2 replication connections required
WARNING: data checksums are not enabled and "wal_log_hints" is "off"
DETAIL: pg_rewind requires "wal_log_hints" to be enabled
NOTICE: standby will attach to upstream node 1
HINT: consider using the -c/--fast-checkpoint option
INFO: would execute:
pg_basebackup -l "repmgr base backup" -D /database/edb/as14 -h postoffline -p 5444 -U repmgr -X stream
INFO: all prerequisites for "standby clone" are met
bash-4.2$
/usr/edb/as14/bin/repmgr -h postoffline -U repmgr -d repmgr -f /etc/repmgr/14/repmgr.conf standby clone
bash-4.2$ /usr/edb/as14/bin/repmgr -h postoffline -U repmgr -d repmgr -f /etc/repmgr/14/repmgr.conf standby clone
NOTICE: destination directory "/database/edb/as14" provided
INFO: connecting to source node
DETAIL: connection string is: host=postoffline user=repmgr dbname=repmgr
DETAIL: current installation size is 102 MB
INFO: replication slot usage not requested; no replication slot will be set up for this standby
NOTICE: checking for available walsenders on the source node (2 required)
NOTICE: checking replication connections can be made to the source server (2 required)
WARNING: data checksums are not enabled and "wal_log_hints" is "off"
DETAIL: pg_rewind requires "wal_log_hints" to be enabled
INFO: checking and correcting permissions on existing directory "/database/edb/as14"
NOTICE: starting backup (using pg_basebackup)...
HINT: this may take some time; consider using the -c/--fast-checkpoint option
INFO: executing:
pg_basebackup -l "repmgr base backup" -D /database/edb/as14 -h postoffline -p 5444 -U repmgr -X stream
NOTICE: standby clone (using pg_basebackup) complete
NOTICE: you can now start your PostgreSQL server
HINT: for example: pg_ctl -D /database/edb/as14 start
HINT: after starting the server, you need to register this standby with "repmgr standby register"
bash-4.2$
[root@postonline ~]# firewall-cmd --add-port=5444/tcp
success
[root@postonline ~]#
bash-4.2$ /usr/edb/as14/bin/pg_ctl -D /database/edb/as14 -l logfile start
waiting for server to start.... done
server started
bash-4.2$ /usr/edb/as14/bin/pg_ctl -D /database/edb/as14 -l logfile status
pg_ctl: server is running (PID: 6344)
/usr/edb/as14/bin/edb-postgres "-D" "/database/edb/as14"
bash-4.2$
/usr/edb/as14/bin/repmgr -f /etc/repmgr/14/repmgr.conf standby register
bash-4.2$ /usr/edb/as14/bin/repmgr -f /etc/repmgr/14/repmgr.conf standby register
INFO: connecting to local node "postonline" (ID: 2)
INFO: connecting to primary database
WARNING: --upstream-node-id not supplied, assuming upstream node is primary (node ID: 1)
INFO: standby registration complete
NOTICE: standby node "postonline" (ID: 2) successfully registered
bash-4.2$
/usr/edb/as14/bin/repmgr -f /etc/repmgr/14/repmgr.conf cluster show
bash-4.2$ /usr/edb/as14/bin/repmgr -f /etc/repmgr/14/repmgr.conf cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string
----+-------------+---------+-----------+-------------+----------+----------+----------+--------------------------------------------------------------
1 | postoffline | primary | * running | | default | 100 | 1 | host=postoffline user=repmgr dbname=repmgr connect_timeout=2
2 | postonline | standby | running | postoffline | default | 100 | 1 | host=postonline user=repmgr dbname=repmgr connect_timeout=2
bash-4.2$
/usr/edb/as14/bin/repmgrd -f /etc/repmgr/14/repmgr.conf
bash-4.2$ /usr/edb/as14/bin/repmgrd -f /etc/repmgr/14/repmgr.conf
[2024-03-03 15:59:52] [NOTICE] repmgrd (repmgrd 5.3.2) starting up
[2024-03-03 15:59:52] [INFO] connecting to database "host=postonline user=repmgr dbname=repmgr connect_timeout=2"
bash-4.2$ [2024-03-03 15:59:52] [ERROR] PID file "/tmp/repmgrd.pid" exists and seems to contain a valid PID
[2024-03-03 15:59:52] [HINT] if repmgrd is no longer alive, remove the file and restart repmgrd
bash-4.2$ [2024-03-03 16:00:18] [INFO] node "postonline" (ID: 2) monitoring upstream node "postoffline" (ID: 1) in normal state
bash-4.2$
/usr/edb/as14/bin/repmgr -f /etc/repmgr/14/repmgr.conf cluster event
bash-4.2$ /usr/edb/as14/bin/repmgr -f /etc/repmgr/14/repmgr.conf cluster event
Node ID | Name | Event | OK | Timestamp | Details
---------+-------------+------------------+----+---------------------+-------------------------------------------------------------------------------------
2 | postonline | repmgrd_start | t | 2024-03-03 15:55:17 | monitoring connection to upstream node "postoffline" (ID: 1)
2 | postonline | standby_register | t | 2024-03-03 15:54:08 | standby registration succeeded; upstream node ID is 1
2 | postonline | standby_clone | t | 2024-03-03 15:40:23 | cloned from host "postoffline", port 5444; backup method: pg_basebackup; --force: N
1 | postoffline | primary_register | t | 2024-03-03 15:03:31 |
1 | postoffline | cluster_created | t | 2024-03-03 15:03:31 |
bash-4.2$
Comments
Post a Comment