官方网站: https://repmgr.org WHAT IS REPMGR? repmgr is an open-source tool suite for managing replication and failover in a cluster of PostgreSQL servers. It enhances PostgreSQL's built-in hot-standby capabilities with tools to set up standby servers, monitor replication, and perform administrative tasks such as failover or manual switchover operations. repmgr has provided advanced support for PostgreSQL's built-in replication mechanisms since they were introduced in 9.0. The current repmgr series, repmgr 5, supports the latest developments in replication functionality introduced from PostgreSQL 9.3 such as cascading replication, timeline switching and base backups via the replication protocol. OPEN SOURCE FROM 2NDQUADRANT repmgr is developed by 2ndQuadrant, the global experts in PostgreSQL support, training, development, migration and consultancy. repmgr is free and open-source software licensed under the GNU Public License (GPL) v3. This means you are free to use and modify repmgr as you see fit, however any modifications you make may only be distributed under the same terms. repmgr compatibility matrix repmgr version Supported? Latest release Supported PostgreSQL versions repmgr 5.x YES 5.0.0 (2019-10-15) 9.3, 9.4, 9.5, 9.6, 10, 11, 12 repmgr 4.x NO 4.4 (2019-06-27) 9.3, 9.4, 9.5, 9.6, 10, 11 repmgr 3.x NO 3.3.2 (2017-05-30) 9.3, 9.4, 9.5, 9.6 repmgr 2.x NO 2.0.3 (2015-04-16) 9.0, 9.1, 9.2, 9.3, 9.4 我们使用 postgresql 12.4 版本,所有使用repmgr 5.x 版本 使用文档为: https://repmgr.org/docs/5.0/index.html 环境描述: repmgr1: 192.168.112.66 centos 7.0 postgresql 12.4 repmgr2: 192.168.112.67 centos 7.0 postgresql 12.4 1.安装 2.1. Requirements for installing repmgr A dedicated system user for repmgr is not required; as many repmgr and repmgrd actions require direct access to the PostgreSQL data directory, these commands should be executed by the postgres user. 我们使用 postgres 用户进行安装. Important yum install flex libselinux-devel libxml2-devel libxslt-devel openssl-devel pam-devel readline-devel 2.3. Installing repmgr from source 获取源码 https://github.com/2ndQuadrant/repmgr 2.3.3. Installation of repmgr from source ./configure make make install 3.1. Prerequisites for setting up a basic replication cluster with repmgr If you want repmgr to copy configuration files which are located outside the PostgreSQL data directory, and/or to test switchover functionality, you will also need passwordless SSH connections between both servers, and rsync should be installed. 两台机器配置一下postgres 用户的 ssh 互信 3.2. PostgreSQL configuration On the primary server, a PostgreSQL instance must be initialised and running. The following replication settings may need to be adjusted: max_wal_senders = 10 max_replication_slots = 10 wal_level = 'hot_standby' hot_standby = on archive_mode = on archive_command = '/bin/true' Tip Rather than editing these settings in the default postgresql.conf file, create a separate file such as postgresql.replication.conf and include it from the end of the main configuration file with: include 'postgresql.replication.conf'. 我们在主库 repmgr1 创建 postgresql.replication.conf 文件,将如上6个参数写入文件中. 编辑 postgresql.conf 文件,在最后一行加入 include 'postgresql.replication.conf' 重启主库进行验证: postgres=# show max_wal_senders; max_wal_senders ----------------- 10 (1 row) 3.3. Create the repmgr user and database createuser -s repmgr createdb repmgr -O repmgr 3.4. Configuring authentication in pg_hba.conf local replication all trust host replication all 127.0.0.1/32 trust host replication all 192.168.112.66/24 trust host replication all 192.168.112.67/24 trust local repmgr all trust host repmgr all 127.0.0.1/32 trust host repmgr all 192.168.112.66/24 trust host repmgr all 192.168.112.67/24 trust 3.6. repmgr configuration file Create a repmgr.conf file on the primary server. The file must contain at least the following parameters: node_id=1 node_name='repmgr1' conninfo='host=repmgr1 user=repmgr dbname=repmgr connect_timeout=2' data_directory='/pgsoft/data' 3.7. Register the primary server [postgres@repmgr1 data]$ repmgr -f /pgsoft/data/repmgr.conf primary register INFO: connecting to primary database... NOTICE: attempting to install extension "repmgr" NOTICE: "repmgr" extension successfully installed NOTICE: primary node record (ID: 1) registered 3.8. Clone the standby server Create a repmgr.conf file on the standby server. node_id=2 node_name='repmgr2' conninfo='host=repmgr2 user=repmgr dbname=repmgr connect_timeout=2' data_directory='/pgsoft/data' Use the --dry-run option to check the standby can be cloned: [postgres@repmgr2 pgsoft]$ repmgr -h repmgr1 -U repmgr -d repmgr -f /pgsoft/repmgr.conf standby clone --dry-run NOTICE: destination directory "/pgsoft/data" provided INFO: connecting to source node DETAIL: connection string is: host=repmgr1 user=repmgr dbname=repmgr DETAIL: current installation size is 31 MB INFO: "repmgr" extension is installed in database "repmgr" INFO: parameter "max_wal_senders" set to 10 NOTICE: checking for available walsenders on the source node (2 required) INFO: sufficient walsenders available on the source node DETAIL: 2 required, 10 available NOTICE: checking replication connections can be made to the source server (2 required) INFO: required number of replication connections could be made to the source server DETAIL: 2 replication connections required NOTICE: standby will attach to upstream node 1 HINT: consider using the -c/--fast-checkpoint option INFO: all prerequisites for "standby clone" are met If no problems are reported, the standby can then be cloned with: [postgres@repmgr2 pgsoft]$ repmgr -h repmgr1 -U repmgr -d repmgr -f /pgsoft/repmgr.conf standby clone NOTICE: destination directory "/pgsoft/data" provided INFO: connecting to source node DETAIL: connection string is: host=repmgr1 user=repmgr dbname=repmgr DETAIL: current installation size is 31 MB NOTICE: checking for available walsenders on the source node (2 required) NOTICE: checking replication connections can be made to the source server (2 required) INFO: creating directory "/pgsoft/data"... NOTICE: starting backup (using pg_basebackup)... HINT: this may take some time; consider using the -c/--fast-checkpoint option INFO: executing: pg_basebackup -l "repmgr base backup" -D /pgsoft/data -h repmgr1 -p 5432 -U repmgr -X stream NOTICE: standby clone (using pg_basebackup) complete NOTICE: you can now start your PostgreSQL server HINT: for example: pg_ctl -D /pgsoft/data start HINT: after starting the server, you need to register this standby with "repmgr standby register" 3.10. Register the standby Register the standby server with: [postgres@repmgr2 pgsoft]$ repmgr -f /pgsoft/repmgr.conf standby register INFO: connecting to local node "repmgr2" (ID: 2) INFO: connecting to primary database WARNING: --upstream-node-id not supplied, assuming upstream node is primary (node ID 1) INFO: standby registration complete NOTICE: standby node "repmgr2" (ID: 2) successfully registered 验证: [postgres@repmgr1 data]$ repmgr -f /pgsoft/data/repmgr.conf cluster show ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string ----+---------+---------+-----------+----------+----------+----------+----------+---------------------------------------------------------- 1 | repmgr1 | primary | * running | | default | 100 | 1 | host=repmgr1 user=repmgr dbname=repmgr connect_timeout=2 2 | repmgr2 | standby | running | repmgr1 | default | 100 | 1 | host=repmgr2 user=repmgr dbname=repmgr connect_timeout=2
repmgr基本配置
来源:这里教程网
时间:2026-03-14 20:16:32
作者:
编辑推荐:
下一篇:
相关推荐
-
雷神推出 MIX PRO II 迷你主机:基于 Ultra 200H,玻璃上盖 + ARGB 灯效
2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英
-
制造商 Musnap 推出彩色墨水屏电纸书 Ocean C:支持手写笔、第三方安卓应用
2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce
热文推荐
- Pgbouncer最佳实践:系列三
Pgbouncer最佳实践:系列三
26-03-14 - 【读书笔记】《PostgreSQL指南-内幕探索》-7.堆内元组和仅索引扫描
- Pgbouncer最佳实践:系列二
Pgbouncer最佳实践:系列二
26-03-14 - 云数据库PostgreSQL版重磅升级开年发布会
云数据库PostgreSQL版重磅升级开年发布会
26-03-14 - RockyLinux邮件用户管理(手把手教你配置和管理Rocky Linux邮件用户)
- 技术干货 | 阿里云数据库PostgreSQL 13大版本揭秘
技术干货 | 阿里云数据库PostgreSQL 13大版本揭秘
26-03-14 - Pgbouncer最佳实践:系列四
Pgbouncer最佳实践:系列四
26-03-14 - Pgbouncer最佳实践:系列一
Pgbouncer最佳实践:系列一
26-03-14 - 详谈pg逻辑复制系列之逻辑复制适用场景及原理介绍(一)
详谈pg逻辑复制系列之逻辑复制适用场景及原理介绍(一)
26-03-14 - 阿里云数据库PostgreSQL 13大版本重磅发布
阿里云数据库PostgreSQL 13大版本重磅发布
26-03-14
