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.
If you’re already familiar with Patroni, think of repmgr as a traditional alternative:
-
- It does not require external consensus tools like etcd. But as a consequence, it lacks protection from split-brain
- It doesn’t expose a REST API.
- It relies on PostgreSQL’s built-in streaming replication and enhances it with tooling for managing replication and promoting nodes.
- It’s written in C and integrates tightly with PostgreSQL.
This blog post discusses integrating repmgr with the Barman backup tool, highlighting that a repmgr switchover necessitates a Barman configuration switchover to backup the primary database.
Prerequisites:
The servers listed below are configured to enhance the discussion about the integration.
-
- Primary (P1) – 172.31.26.38
- Standby (P2) – 172.31.21.75
- Barman (pg16_rep) – 172.31.47.42
Process:
The blog post has been divided into several sections.
Initial setup: Configuring a repmgr primary-standby cluster
1 2 3 4 5 6 7 8 9 10 11 12 13 |
node_id=1 node_name='p1' conninfo='host=p1 port=5432 user=repmgr dbname=repmgr connect_timeout=2' data_directory='/var/lib/postgresql/16/main' pg_bindir='/usr/lib/postgresql/16/bin' location='dc1' #Switchover service_start_command='sudo systemctl start postgresql' service_stop_command='sudo systemctl stop postgresql' service_restart_command='sudo systemctl restart postgresql'#AutoFailover failover=automatic promote_command='/usr/lib/postgresql/16/bin/repmgr standby promote -f /etc/repmgr.conf --log-to-file' follow_command='/usr/lib/postgresql/16/bin/repmgr standby follow -f /etc/repmgr.conf --log-to-file --upstream-node-id=%n' |
The repmgr cluster status is shown below.
1 2 3 4 5 |
postgres@ip-172-31-21-75:~$ repmgr -f /etc/repmgr.conf cluster show ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string ----+------+---------+-----------+----------+----------+----------+----------+--------------------------------------------------------------- 1 | p1 | primary | * running | | dc1 | 100 | 7 | host=p1 port=5432 user=repmgr dbname=repmgr connect_timeout=2 2 | p2 | standby | running | p1 | dc1 | 100 | 7 | host=p2 port=5432 user=repmgr dbname=repmgr connect_timeout=2 |
Integrating Barman: Key parameters and Barman-CLI installation
We introduced the Barman parameter for repmgr, which will help to integrate repmgr with Barman. Below are the repmgr configuration parameters to integrate Barman:
You need to add the configuration below to the repmgr.conf file of each DB server.
1 2 3 |
barman_server='pg16_rep' restore_command='/usr/bin/barman-wal-restore 172.31.47.42 pg16_rep %f %p' |
To let the repmgr accept these parameters, follow the steps below.
Install the barman CLI and allow passwordless SSH authentication between the DB and Barman servers.
To install the barman CLI on Ubuntu OS and enable restore_command, execute the following command: You must install barman-wal-restore on the database server. The barman-cli package will include barman-wal-restore.
1 |
sudo apt install barman-cli |
Once the repmgr.conf file is configured, you need to take a barman full backup from the current primary database.
Configuring Barman for full backups
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[pg16_rep] description = "Database backup of PG16" ssh_command = ssh -q postgres@172.31.26.38 conninfo = host=172.31.26.38 port=5432 user=barman dbname=postgres streaming_conninfo = host=172.31.26.38 port=5432 user=streaming_barman dbname=postgres backup_method = rsync reuse_backup = link backup_options = concurrent_backup archiver = off streaming_archiver=on path_prefix = "/usr/lib/postgresql/16/bin/" create_slot = auto slot_name = pg16_server_rep |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
barman@ip-172-31-47-42:~$ barman check pg16_rep Server pg16_rep: PostgreSQL: OK superuser or standard user with backup privileges: OK PostgreSQL streaming: OK wal_level: OK replication slot: OK directories: OK retention policy settings: OK backup maximum age: OK (no last_backup_maximum_age provided) backup minimum size: OK (29.7 MiB) wal maximum age: OK (no last_wal_maximum_age provided) wal size: OK (0 B) compression settings: OK failed backups: OK (there are 0 failed backups) minimum redundancy requirements: OK (have 6 backups, expected at least 0) ssh: OK (PostgreSQL server) systemid coherence: OK pg_receivexlog: OK pg_receivexlog compatible: OK receive-wal running: OK archiver errors: OK |
1 2 3 4 5 6 7 8 9 10 11 12 |
barman@ip-172-31-47-42:~$ barman backup pg16_rep Starting backup using rsync-concurrent method for server pg16_rep in /var/lib/barman/pg16_rep/base/20250521T123002 Backup start at LSN: 0/1100AC20 (000000070000000000000011, 0000AC20) Starting backup copy via rsync/SSH for 20250521T123002 Copy done (time: 1 second) Asking PostgreSQL server to finalize the backup. Backup size: 29.7 MiB. Actual size on disk: 46.7 KiB (-99.85% deduplication ratio). Backup end at LSN: 0/1100AD08 (000000070000000000000011, 0000AD08) Backup completed (start time: 2025-05-21 12:30:02.691271, elapsed time: 2 seconds) WARNING: IMPORTANT: this backup is classified as WAITING_FOR_WALS, meaning that Barman has not received yet all the required WAL files for the backup consistency. This is a common behaviour in concurrent backup scenarios, and Barman automatically set the backup as DONE once all the required WAL files have been archived. Hint: execute the backup command with '--wait' |
Testing the integration: Cloning a standby with repmgr and Barman
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
repmgr -h p1 -U repmgr -d repmgr -p 5432 -f /etc/repmgr.conf standby clone --force NOTICE: destination directory "/var/lib/postgresql/16/main" provided INFO: connecting to Barman server to verify backup for "pg16_rep" WARNING: directory "/var/lib/postgresql/16/main" exists but is not empty NOTICE: -F/--force provided - deleting existing data directory "/var/lib/postgresql/16/main" INFO: creating directory "/var/lib/postgresql/16/main/repmgr"... INFO: connecting to Barman server to fetch server parameters INFO: connecting to source node DETAIL: connection string is: host=p1 user=repmgr port=5432 dbname=repmgr DETAIL: current installation size is 29 MB INFO: replication slot usage not requested; no replication slot will be set up for this standby WARNING: data checksums are not enabled and "wal_log_hints" is "off" DETAIL: pg_rewind requires "wal_log_hints" to be enabled NOTICE: retrieving backup from Barman... receiving file list ... 1289 files to consider |
Automating switchover: Configuring repmgr and Barman for seamless failover
After the standby has been successfully cloned, you can initiate a switchover so that the Barman can begin taking backups from the new primary. For this, you need to add the following parameters to the repmgr.conf file of all the DB servers.
1 2 3 4 |
#Barman configuration switchover event_notification_command='ssh [email protected] barman config-switch pg16_rep pg16_rep_model' # same but for original primary, reset to default parameters event_notification_command='ssh [email protected] barman config-switch pg16_rep --reset'# events that will trigger the notification event_notifications='standby_promote,repmgrd_failover_promote' |
The event_notification_command will enable a switchover of the barman configuration, followed by a switchover or failover in the repmgr cluster. The barman config-switch command specified in the event_notification_command parameter initiates a switchover of Barman, allowing it to start taking backups from the new primary database. This is necessary because the defined model contains the details of the standby database, which will become the new primary after promotion.
1 |
barman config-switch pg16_rep pg16_rep_model |
Let’s perform a repmgr switchover to see the impact on the barman.
Before this, we must define a barman model configuration file with a feature to switch the barman configuration on the fly. The configuration file Barman model is: /etc/barman.d/pg16_rep_model.conf.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[pg16_rep_model] description = "Database backup of PG16" ssh_command = ssh -q postgres@172.31.21.75 streaming_conninfo = host=172.31.21.75 port=5432 user=streaming_barman dbname=postgres conninfo = host=172.31.21.75 port=5432 user=barman dbname=postgres backup_method = rsync reuse_backup = link backup_options = concurrent_backup archiver = off streaming_archiver=on path_prefix = "/usr/lib/postgresql/16/bin/" create_slot = auto slot_name = pg16_server_rep model=true cluster=pg16_rep |
After configuring the Barman model, we are ready to perform a switchover using repmgr.
Before switchover:
1 2 3 4 5 6 |
postgres@ip-172-31-21-75:~$ repmgr -f /etc/repmgr.conf cluster show ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string ----+------+---------+-----------+----------+----------+----------+----------+--------------------------------------------------------------- 1 | p1 | primary | * running | | dc1 | 100 | 7 | host=p1 port=5432 user=repmgr dbname=repmgr connect_timeout=2 2 | p2 | standby | running | p1 | dc1 | 100 | 7 | host=p2 port=5432 user=repmgr dbname=repmgr connect_timeout=2 |
Barman Wal Streaming output before switchover:
1 |
barman 403461 403459 0 15:22 ? 00:00:00 /usr/lib/postgresql/17/bin/pg_receivewal --dbname=dbname=replication host=172.31.26.38 options=-cdatestyle=iso port=5432 replication=true user=streaming_barman application_name=barman_receive_wal --verbose --no-loop --no-password --directory=/var/lib/barman/pg16_rep/streaming --slot=pg16_server_rep |
Repmgr switchover:
1 |
postgres@ip-172-31-21-75:~$ repmgr -f /etc/repmgr.conf standby switchover |
Cluster status after switchover:
1 2 3 4 5 6 |
postgres@ip-172-31-21-75:~$ repmgr -f /etc/repmgr.conf cluster show ID | Name | Role | Status | Upstream | Location | Priority | Timeline | Connection string ----+------+---------+-----------+----------+----------+----------+----------+--------------------------------------------------------------- 1 | p1 | standby | running | p2 | dc1 | 100 | 8 | host=p1 port=5432 user=repmgr dbname=repmgr connect_timeout=2 2 | p2 | primary| * running | | dc1 | 100 | 8 | host=p2 port=5432 user=repmgr dbname=repmgr connect_timeout=2 |
Barman Wal streaming output after switchover:
1 |
barman 403461 403459 0 15:22 ? 00:00:00 /usr/lib/postgresql/17/bin/pg_receivewal --dbname=dbname=replication host=172.31.21.75 options=-cdatestyle=iso port=5432 replication=true user=streaming_barman application_name=barman_receive_wal --verbose --no-loop --no-password --directory=/var/lib/barman/pg16_rep/streaming --slot=pg16_server_rep |
The database switchover triggered a change in theBarman, initiating the WAL segment streaming from the new primary server along a new timeline.
I hope this blog aids you in understanding the essential idea of repmgr-Barman integration and its switchover. For eager learners, we offer our PostgreSQL training course. This instructor-led program covers all the topics mentioned above and includes hands-on labs and expert guidance. Find more details and register at percona.com/training.
So, what’s next for your PostgreSQL infrastructure? A truly enterprise-grade environment requires looking at the full picture.
Our PostgreSQL Resource Center is designed to help you master every aspect of running PostgreSQL in production, from cost control to compliance. Explore our resource below to learn how to:
-
Cut costs: Design and optimize a self-managed environment efficiently.
-
Build smarter: Get our buyer’s guide for evaluating enterprise solutions and see how Percona compares.
-
Stay secure: Learn how to meet strict compliance standards without proprietary upsells.
-
Avoid lock-in: See how you can simplify PostgreSQL in the cloud with total freedom.
Further reading
- https://docs.pgbarman.org/release/3.12.0/user_guide/configuration.html
- https://www.repmgr.org/docs/current/cloning-from-barman.html
- https://www.repmgr.org/docs/4.0/event-notifications.html
- https://docs.pgbarman.org/release/3.14.0/user_guide/commands.html#barman-config-switch