repmgr promote

primary:vlnx107001
slave:vlnx107002
slave:vlnx107003

一、
1、查看当前集群状态
repmgr -f /etc/repmgr/9.6/repmgr.conf  cluster show;

2、模拟停止primary
[postgres@vlnx107001 ~]$ pg_ctl -D  $PGDATA -m fast stop

3、提升备用节点
[postgres@vlnx107002 ~]$ repmgr -f /etc/repmgr/9.6/repmgr.conf  standby promote
任何其他备用服务器节点都将遵循新的服务器作为同步源,如果repmgrd 处于活动状态,它将自动处理。
请注意,repmgr将等待promote_check_timeout秒(默认值:60秒)以验证备用数据库是否已升级,并且每检查一次promotion_check_interval秒数(默认值:1秒)。这两个值都可以在repmgr.conf中定义。

4、让从节点从新primary上同步数据,在从节点上执行下列命令即可:
[postgres@vlnx107003 ~]$ repmgr -f /etc/repmgr/9.6/repmgr.conf  standby follow
该命令将强制重启必须运行的备用服务器。它只能用于将活动备用数据库附加到当前主节点(而不是另一个备用数据库)。


二、
将vlnx107001 节点以 standby 角色重新加入到 集群中;
总的思路:
这是一个两阶段的过程。首先,失败的主数据目录必须与当前的主数据库重新同步; 其次,失败的主要需要重新注册为备用。
pg9.5以后提供了 pg_rewind应用程序,让我们更快更方便的实现

[postgres@vlnx107001 data]$ repmgr -f /etc/repmgr/9.6/repmgr.conf node rejoin -d 'host=172.31.107.2 dbname=repmgr user=repmgr' --force-rewind --config-files=postgresql.conf,postgresql.auto.conf --verbose --dry-run

注意:如果不执行本脚本,而是直接使用 pg_ctl -D $PGDAT start         启动,则会导致 变相的 “脑裂”,即 vlnx107001 和 vlnx107002 都显示 primary

这时候需要做的是,将 recovery.conf 重命名或删除,然后停止 postgresql服务;最后再执行:
repmgr -f /etc/repmgr/9.6/repmgr.conf node rejoin -d 'host=172.31.107.2 dbname=repmgr user=repmgr' --force-rewind --config-files=postgresql.conf,postgresql.auto.conf --verbose --dry-run
验证是否 可以重新加入,如果提示重新加入的先决条件得到满足,则就可以执行 remgr rejoin 命令了

[postgres@vlnx107001 data]$ repmgr -f /etc/repmgr/9.6/repmgr.conf node rejoin -d 'host=172.31.107.2 dbname=repmgr user=repmgr' --force-rewind --config-files=postgresql.conf,postgresql.auto.conf --verbose

注意:
要使用 pg_rewind应用程序 必须在 postgresql.config 中启用 wal_log_hints=on
如果需要使用pg_rewind,请传递命令行选项--force-rewind,它将告诉repmgr 执行pg_rewind以确保节点可以成功重新加入。

请注意,如果执行pg_rewind并实际执行回滚操作,PostgreSQL数据目录中的所有配置文件将被来自源服务器的配置文件覆盖。

为防止发生这种情况,请使用--config-file命令行选项提供逗号分隔的文件列表以保留该列表; 指定的文件将被归档到一个临时目录(其父目录可以使用--config-archive-dir指定 )并在完成倒带操作后恢复。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值