跳转到主要内容

repmgr

PostgreSQL复制管理组件

概览

扩展包名版本分类许可证语言
repmgr5.5.1ETLGPL-3.0C
ID扩展名BinLibLoadCreateTrustReloc模式
9710repmgr是是是是否否repmgr

版本

类型仓库版本PG 大版本包名依赖
EXTPGDG5.5.11817161514repmgr-
RPMPGDG5.5.11817161514repmgr_$v-
DEBPGDG5.5.11817161514postgresql-$v-repmgr-
OS / PGPG19PG18PG17PG16PG15
el8.x86_64N/A
el8.aarch64N/A
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64
u26.x86_64
u26.aarch64

构建

您可以使用 pig build 命令构建 repmgr 扩展的 RPM / DEB 包:

pig build pkg repmgr         # 构建 RPM / DEB 包

安装

您可以直接安装 repmgr 扩展包的预置二进制包,首先确保 PGDG 仓库已经添加并启用:

pig repo add pgdg -u          # 添加 PGDG 仓库并更新缓存

使用 pig 或者是 apt/yum/dnf 安装扩展:

安装
pig install repmgr;          # 当前活跃 PG 版本安装
pig
pig ext install -y repmgr -v 19  # PG 19
pig ext install -y repmgr -v 18  # PG 18
pig ext install -y repmgr -v 17  # PG 17
pig ext install -y repmgr -v 16  # PG 16
pig ext install -y repmgr -v 15  # PG 15
dnf
dnf install -y repmgr_19       # PG 19
dnf install -y repmgr_18       # PG 18
dnf install -y repmgr_17       # PG 17
dnf install -y repmgr_16       # PG 16
dnf install -y repmgr_15       # PG 15
apt
apt install -y postgresql-19-repmgr   # PG 19
apt install -y postgresql-18-repmgr   # PG 18
apt install -y postgresql-17-repmgr   # PG 17
apt install -y postgresql-16-repmgr   # PG 16
apt install -y postgresql-15-repmgr   # PG 15

预加载配置:

shared_preload_libraries = 'repmgr';

创建扩展:

CREATE EXTENSION repmgr;

用法

来源:

repmgr 管理 PostgreSQL 物理复制、监控与故障切换。发行版 5.5.1 支持 PostgreSQL 13–18,SQL 扩展版本仍为 5.5;它修复了向外部通知命令替换参数时的转义问题。集群各节点应使用同一 repmgr 发布版本。

启用

使用独立的元数据数据库与管理角色,并配置复制连接及所需的 SSH 访问。上游快速入门使用超级用户角色;普通角色需要为高权限操作提供 --superuser。以下 SQL 应在元数据数据库内以足够权限执行:

CREATE EXTENSION repmgr;

配置

在每个节点上创建 repmgr.conf:

node_id=1
node_name='node1'
conninfo='host=node1 dbname=repmgr user=repmgr'
data_directory='/var/lib/postgresql/data'

注册主节点

repmgr -f /etc/repmgr.conf primary register

克隆并注册备节点

# Clone from primary
repmgr -h primary-host -U repmgr -d repmgr -f /etc/repmgr.conf standby clone

# Start the standby
pg_ctl -D /var/lib/postgresql/data start

# Register the standby
repmgr -f /etc/repmgr.conf standby register

监控

# Show cluster status
repmgr -f /etc/repmgr.conf cluster show

# Show replication status
repmgr -f /etc/repmgr.conf node status

手动切换

将备节点提升为主节点(计划性切换):

repmgr -f /etc/repmgr.conf standby switchover

使用 repmgrd 自动故障转移

使用 repmgrd 前,在每个节点配置以下参数并重启 PostgreSQL:

shared_preload_libraries = 'repmgr'

在每个节点上启动 repmgr 守护进程:

repmgrd -f /etc/repmgr.conf

在 repmgr.conf 中配置故障转移:

failover='automatic'
promote_command='repmgr standby promote -f /etc/repmgr.conf'
follow_command='repmgr standby follow -f /etc/repmgr.conf --upstream-node-id=%n'

关键命令

  • repmgr primary register - 注册主节点
  • repmgr standby clone - 从主节点克隆备节点
  • repmgr standby register - 注册备节点
  • repmgr standby promote - 将备节点提升为主节点
  • repmgr standby follow - 跟随新的主节点
  • repmgr standby switchover - 计划性切换
  • repmgr cluster show - 显示集群状态
  • repmgr cluster event - 显示集群事件
  • repmgr node check - 节点健康检查

5.5.1 升级

按升级指南暂停或停止自动故障转移,更新各节点的程序,再重启正在运行的 repmgrd 并检查集群状态。5.5.0 与 5.5.1 的 SQL 版本均为 5.5,不要尝试更新到不存在的 SQL 版本 5.5.1;从更早的 SQL 版本升级时,应遵循对应的扩展升级链。

这个页面对您有帮助吗?

表格阅读器