【postgresql】repmgr failover切换

1.主库关闭 

[pgsql@pg1:/home/pgsql]$pg_ctl stop 
waiting for server to shut down........ done
server stopped

2.检查集群状态 

[pgsql@pg2:/home/pgsql]$repmgr -f /postgresql/app/postgresql/repmgr.conf cluster show
 ID | Name | Role    | Status        | Upstream | Location | Priority | Timeline | Connection string                                                      
----+------+---------+---------------+----------+----------+----------+----------+-------------------------------------------------------------------------
 1  | pg1  | primary | ? unreachable | ?        | default  | 100      |          | host=192.168.1.10 port=5432 user=repmgr dbname=repmgr connect_timeout=2
 2  | pg2  | standby |   running     | ? pg1    | default  | 100      | 2        | host=192.168.1.11 port=5432 user=repmgr dbname=repmgr connect_timeout=2
 3  | pg3  | standby |   running     | ? pg1    | default  | 100      | 3        | host=192.168.1.12 port=5432 user=repmgr dbname=repmgr connect_timeout=2
 4  | pg4  | witness | * running     | pg3      | default  | 0        | n/a      | host=192.168.1.13 port=5432 user=repmgr dbname=repmgr connect_timeout=2

WARNING: following issues were detected
  - unable to connect to node "pg1" (ID: 1)
  - node "pg1" (ID: 1) is registered as an active primary but is unreachable
  - unable to connect to node "pg2" (ID: 2)'s upstream node "pg1" (ID: 1)
  - unable to determine if node "pg2" (ID: 2) is attached to its upstream node "pg1" (ID: 1)
  - unable to connect to node "pg3" (ID: 3)'s upstream node "pg1" (ID: 1)
  - unable to determine if node "pg3" (ID: 3) is attached to its upstream node "pg1" (ID: 1)

HINT: execute with --verbose option to see connection error messages

3.切换pg2位主节点 

(1)切换Pg2为新的主 
[pgsql@pg2:/home/pgsql]$repmgr -f /postgresql/app/postgresql/repmgr.conf --siblings-follow standby promote
NOTICE: promoting standby to primary
DETAIL: promoting server "pg2" (ID: 2) using "/postgresql/app/postgresql/bin/pg_ctl -w -D /postgresql/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 "pg2" (ID: 2) was successfully promoted to primary
NOTICE: executing STANDBY FOLLOW on 1 of 1 siblings
INFO: STANDBY FOLLOW successfully executed on all reachable sibling nodes
(2)检查 
[pgsql@pg2:/home/pgsql]$repmgr -f /postgresql/app/postgresql/repmgr.conf cluster show
 ID | Name | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string                                                      
----+------+---------+-----------+----------+----------+----------+----------+-------------------------------------------------------------------------
 1  | pg1  | primary | - failed  | ?        | default  | 100      |          | host=192.168.1.10 port=5432 user=repmgr dbname=repmgr connect_timeout=2
 2  | pg2  | primary | * running |          | default  | 100      | 5        | host=192.168.1.11 port=5432 user=repmgr dbname=repmgr connect_timeout=2
 3  | pg3  | standby |   running | pg2      | default  | 100      | 3        | host=192.168.1.12 port=5432 user=repmgr dbname=repmgr connect_timeout=2
 4  | pg4  | witness | * running | pg3      | default  | 0        | n/a      | host=192.168.1.13 port=5432 user=repmgr dbname=repmgr connect_timeout=2

WARNING: following issues were detected
  - unable to connect to node "pg1" (ID: 1)

HINT: execute with --verbose option to see connection error messages

4.写入数据测试 

(1)写入数据 
sspudb=> insert into my_test3 values(4,'xsq4'),(5,'xsq5');
INSERT 0 2
sspudb=> select * from my_test3;
 id | name 
----+------
  1 | xsq2
  2 | xsq2
  3 | xsq3
  4 | xsq4
  5 | xsq5
(5 rows)
(2)从库数据检查 
[pgsql@pg3:/home/pgsql]$psql -U sspu -d sspudb
Password for user sspu: 
psql (15.3)
Type "help" for help.

sspudb=> select * from my_test3;
 id | name 
----+------
  1 | xsq2
  2 | xsq2
  3 | xsq3
  4 | xsq4
  5 | xsq5
(5 rows)

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值