Ver configuración parte 1
Ver configuración parte 2
Comprobación previa estado cluster:
[postgres@postgres1 ~]$ repmgr cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string
----+-----------+---------+-----------+-----------+----------+----------+----------+----------------------------------------------
1 | postgres1 | primary | * running | | default | 100 | 1 | host=192.168.0.101 user=repmgr dbname=repmgr
2 | postgres2 | standby | running | postgres1 | default | 100 | 1 | host=192.168.0.102 user=repmgr dbname=repmgr
3 | postgres3 | standby | running | postgres1 | default | 100 | 1 | host=192.168.0.103 user=repmgr dbname=repmgr
Desde el nodo que promocionará ejecutamos de prueba:
[postgres@postgres2 ~]$ repmgr standby switchover --siblings-follow --force-rewind --dry-run
NOTICE: checking switchover on node "postgres2" (ID: 2) in --dry-run mode
INFO: prerequisites for using pg_rewind are met
INFO: SSH connection to host "192.168.0.101" succeeded
INFO 2>/dev/null
INFO: able to execute "repmgr" on remote host "192.168.0.101"
INFO: all sibling nodes are reachable via SSH
INFO: 2 walsenders required, 10 available
INFO: demotion candidate is able to make replication connection to promotion candidate
INFO: 0 pending archive files
INFO: replication lag on this standby is 0 seconds
INFO: 2 replication slots required, 10 available
NOTICE: local node "postgres2" (ID: 2) would be promoted to primary; current primary "postgres1" (ID: 1) would be demoted to standby
INFO: following shutdown command would be run on node "postgres1":
"sudo /bin/systemctl stop postgresql-13"
INFO: parameter "shutdown_check_timeout" is set to 60 seconds
INFO: prerequisites for executing STANDBY SWITCHOVER are met
Lo ejecutamos en real:
[postgres@postgres2 ~]$ repmgr standby switchover --siblings-follow --force-rewind
NOTICE: executing switchover on node "postgres2" (ID: 2)
NOTICE: local node "postgres2" (ID: 2) will be promoted to primary; current primary "postgres1" (ID: 1) will be demoted to standby
NOTICE: stopping current primary node "postgres1" (ID: 1)
NOTICE: issuing CHECKPOINT on node "postgres1" (ID: 1)
DETAIL: executing server command "sudo /bin/systemctl stop postgresql-13"
INFO: checking for primary shutdown; 1 of 60 attempts ("shutdown_check_timeout")
NOTICE: current primary has been cleanly shut down at location 0/D000028
NOTICE: promoting standby to primary
DETAIL: promoting server "postgres2" (ID: 2) using "/usr/pgsql-13/bin/pg_ctl -D /var/lib/pgsql/13/data promote"
waiting for server to promote.... done
server promoted
NOTICE: waiting up to 60 seconds (parameter "promote_check_timeout") for promotion to complete
NOTICE: STANDBY PROMOTE successful
DETAIL: server "postgres2" (ID: 2) was successfully promoted to primary
NOTICE: issuing CHECKPOINT on node "postgres2" (ID: 2)
ERROR: unable to execute CHECKPOINT
INFO: local node 1 can attach to rejoin target node 2
DETAIL: local node's recovery point: 0/D000028; rejoin target node's fork point: 0/D0000A0
INFO: creating replication slot as user "repmgr"
NOTICE: setting node 1's upstream to node 2
WARNING: unable to ping "host=192.168.0.101 user=repmgr dbname=repmgr"
DETAIL: PQping() returned "PQPING_NO_RESPONSE"
NOTICE: starting server using "sudo /bin/systemctl start postgresql-13"
WARNING: node "postgres1" not found in "pg_stat_replication"
NOTICE: replication slot "repmgr_slot_2" deleted on node 1
WARNING: 1 inactive replication slots detected
DETAIL: inactive replication slots:
- repmgr_slot_3 (physical)
HINT: these replication slots may need to be removed manually
NOTICE: NODE REJOIN successful
DETAIL: node 1 is now attached to node 2
WARNING: node "postgres1" not found in "pg_stat_replication"
INFO: waiting for node "postgres1" (ID: 1) to connect to new primary; 1 of max 60 attempts (parameter "node_rejoin_timeout")
DETAIL: checking for record in node "postgres2"'s "pg_stat_replication" table where "application_name" is "postgres1"
NOTICE: node "postgres2" (ID: 2) promoted to primary, node "postgres1" (ID: 1) demoted to standby
NOTICE: executing STANDBY FOLLOW on 1 of 1 siblings
INFO: STANDBY FOLLOW successfully executed on all reachable sibling nodes
NOTICE: switchover was successful
DETAIL: node "postgres2" is now primary and node "postgres1" is attached as standby
NOTICE: STANDBY SWITCHOVER has completed successfully
Comprobación del cluster posterior (atención porque el nodo postgres3 cambia a apuntar a la nueva primary – siblings_follow -):
[postgres@postgres1 ~]$ repmgr cluster show
ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string
----+-----------+---------+-----------+-----------+----------+----------+----------+----------------------------------------------
1 | postgres1 | standby | running | postgres2 | default | 100 | 1 | host=192.168.0.101 user=repmgr dbname=repmgr
2 | postgres2 | primary | * running | | default | 100 | 2 | host=192.168.0.102 user=repmgr dbname=repmgr
3 | postgres3 | standby | running | postgres2 | default | 100 | 2 | host=192.168.0.103 user=repmgr dbname=repmgr
[postgres@postgres1 ~]$ repmgr cluster event
Node ID | Name | Event | OK | Timestamp | Details
---------+-----------+--------------------+----+---------------------+--------------------------------------------------------------------------------------------
3 | postgres3 | standby_follow | t | 2021-01-07 17:33:20 | standby attached to upstream node "postgres2" (ID: 2)
2 | postgres2 | standby_switchover | t | 2021-01-07 17:33:19 | node "postgres2" (ID: 2) promoted to primary, node "postgres1" (ID: 1) demoted to standby
2 | postgres2 | standby_promote | t | 2021-01-07 17:33:16 | server "postgres2" (ID: 2) was successfully promoted to primary
3 | postgres3 | standby_register | t | 2021-01-07 17:09:56 | standby registration succeeded; upstream node ID is 1
3 | postgres3 | standby_clone | t | 2021-01-07 17:08:55 | cloned from host "192.168.0.101", port 5432; backup method: pg_basebackup; --force: N
2 | postgres2 | standby_register | t | 2021-01-07 17:05:09 | standby registration succeeded; upstream node ID is 1
2 | postgres2 | standby_clone | t | 2021-01-07 17:01:55 | cloned from host "192.168.0.101", port 5432; backup method: pg_basebackup; --force: N
2 | postgres2 | standby_clone | t | 2021-01-07 16:59:49 | cloned from host "192.168.0.101", port 5432; backup method: pg_basebackup; --force: N
1 | postgres1 | primary_register | t | 2021-01-07 16:39:53 |
1 | postgres1 | cluster_created | t | 2021-01-07 16:39:53 |
Ver failover