postgresql 12 and later
repmgr主从高可用配置、switchover切换和failover切换
repmgr是一套开源工具,用于管理PostgreSQL服务器群集内的复制和故障转移。它支持并增强了PostgreSQL的内置流复制,该复制流提供了一个读/写主服务器以及一个或多个只读备用数据库,其中包含主服务器数据库的近实时副本。可以设置热备份服务器、监控复制、执行管理任务(故障转移、手工切换等)。
repmgr primary register 安装pg的repmgr扩展并注册为主节点 repmgr primary unregister 注销不活动的主节点 repmgr standby clone 从其他节点复制数据到从节点 repmgr standby register 注册从节点(添加从的信息到repmgr元数据) repmgr standby unregister repmgr元数据中移除从的信息 repmgr standby promote 将从提升为主 repmgr standby follow 将从跟随新主 repmgr standby switchover 将从提升为主并将主降级为从 repmgr witness register 注册一个观察节点 repmgr witness unregister 移除一个观察节点 repmgr node status 显示节点的基本信息和复制状态 repmgr node check 从复制的角度对节点进行健康监测 repmgr node rejoin 重新加入一个失效节点到集群 repmgr cluster show 显示所有集群中注册的节点信息 repmgr cluster matrix 所有节点运行show并汇总 repmgr cluster crosscheck 节点间两两交叉监测连接 repmgr cluster event 输出时间记录 repmgr cluster cleanup 清理监控历史

repmgr高可用主从配置

[root@ora11g-node01 postgres]# ls -l repmgr-master.zip
-rw-r--r-- 1 root root 561946 Jun 20 23:02 repmgr-master.zip
[root@ora11g-node01 repmgr-master]# unzip repmgr-master.zip
进入解压目录安装
[postgres@ora11g-node01 repmgr-master]$ ./configure --prefix=/usr/share/postgresql-12.5
[postgres@ora11g-node01 repmgr-master]$ make
[postgres@ora11g-node01 repmgr-master]$ make install
[postgres@ora11g-node01 12]$ more /data/pgsql/pg_hba.conf
。。。。。
host repmgr repmgr 192.168.56.50/32 trust
host repmgr repmgr 192.168.56.51/32 trust
host replication repmgr 192.168.56.50/32 trust
host replication repmgr 192.168.56.51/32 trust
host all all 0.0.0.0/0 md5
[postgres@ora11g-node01 12]$ pg_ctl reload
server signaled
createuser -s repmgr
createdb repmgr -O repmgr
alter user repmgr superuser;
repmgr -h 192.168.56.50 -Urepmgr standby clone -F -D /data/pgsql
[postgres@ora11g-node01 repmgr-master]$ mkdir -p /etc/repmgr/12
[postgres@ora11g-node01 repmgr-master]$ vi /etc/repmgr/12/repmgr.conf
node_id=1
node_name=ora11g-node01
conninfo='host=192.168.56.50 port=5432 user=repmgr dbname=repmgr connect_timeout=20'
data_directory='/data/pgsql'
pg_bindir='/usr/share/postgresql-12.5/bin'
replication_user='repmgr'
replication_type='physical'
use_replication_slots=yes
failover=automatic
reconnect_attempts=6
reconnect_interval=5
promote_command='repmgr standby promote -f /etc/repmgr/12/repmgr.conf --log-to-file'
follow_command='repmgr standby follow -f /etc/repmgr/12/repmgr.conf --log-to-file --upstream-node-id=%n'
log_file='/home/postgres/repmgr.log'