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.

    1. Primary (P1) – 172.31.26.38
    2. Standby (P2) – 172.31.21.75
    3. 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

We set up the repmgr cluster featuring one primary and one standby based on the following configuration. Sample of repmgr.conf used to configure REPMGR:

The repmgr cluster status is shown below.

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.


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.


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

The configuration file of barman server is: /etc/barman.d/pg16_rep.conf
The barman check pg16_rep command output after configuring Barman to take a backup from the primary.
Once Barman is configured, you need to perform a full backup from the primary database server.

Testing the integration: Cloning a standby with repmgr and Barman

Once a complete Barman backup is taken, we can utilize the repmgr clone command to verify if repmgr is successfully recovering the standby via Barman. This allows us to clearly observe the application of the Barman backup during the database cloning process.

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.

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.

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.

After configuring the Barman model, we are ready to perform a switchover using repmgr.

Before switchover:

Barman Wal Streaming output before switchover:

Repmgr switchover:

Cluster status after switchover:

Barman Wal streaming output after switchover:

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

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments