tomasz-gintowt.medium.com 3 min read Original Source

PostgreSQL High Availability: repmgr vs Patroni vs pg_auto_failover

High Availability is one of the first things we think about when building a production PostgreSQL environment. Nobody wants their database to become a single point of failure.

Over the years, I’ve worked with different HA solutions. Each has its strengths, and none of them is perfect for every situation.

In this article, we’ll compare three popular open-source solutions:

  • repmgr
  • Patroni
  • pg_auto_failover

We’ll see how they work, when to use them, and which one might fit your environment.

The Goal

All three solutions try to solve the same problem.

If the primary PostgreSQL server fails, another server should automatically become the new primary.

The difference is how they detect failures and decide when to promote a standby.

1. repmgr

repmgr has been around for many years and is probably the best-known PostgreSQL replication manager.

It uses PostgreSQL streaming replication and provides tools for:

  • cloning standbys
  • monitoring replication
  • automatic failover
  • planned switchovers
  • cluster status

Typical architecture:

The Witness node does not store database data.

Its only job is helping avoid split-brain situations during network problems.

How failover works

  1. Primary becomes unavailable.
  2. repmgrd detects the failure.
  3. Standby checks the Witness.
  4. If it is safe, the standby promotes itself.

Advantages

  • Very mature
  • Easy to understand
  • Lightweight
  • No external distributed system required
  • Excellent documentation

Disadvantages

  • Fewer automation features than Patroni
  • Applications still need a way to reconnect
  • Witness node adds another server to manage

2. Patroni

Patroni is currently one of the most popular HA solutions for PostgreSQL.

Unlike repmgr, Patroni does not make decisions alone.

It stores cluster state inside a Distributed Configuration Store (DCS) such as:

  • etcd
  • Consul
  • ZooKeeper
  • Kubernetes

Architecture:

The PostgreSQL servers continuously communicate with the DCS.

If the primary disappears, Patroni asks the DCS which server should become the new leader.

Leader Election

Think of the DCS as a referee.

Instead of each PostgreSQL server making its own decision, everyone asks the referee.

Only one server is allowed to become the leader.

This greatly reduces the chance of split-brain.

Advantages

  • Excellent automation
  • Very reliable leader election
  • Kubernetes support
  • REST API
  • Large community
  • Works well for large clusters

Disadvantages

  • More complex
  • Requires etcd or Consul

3. pg_auto_failover

pg_auto_failover is developed by Microsoft.

Its main goal is making PostgreSQL HA simple.

Instead of a witness or distributed key-value store, it introduces a Monitor node.

Architecture:

The Monitor watches every PostgreSQL node.

When something goes wrong, it tells the standby whether it can safely become the new primary.

Unlike the Witness in repmgr, the Monitor is an active part of the cluster and coordinates node state changes.

Advantages

  • Easy installation
  • Automatic failover
  • Automatic state management
  • No etcd required
  • Good for small and medium clusters

Disadvantages

  • Smaller community
  • Fewer real-world deployments than Patroni
  • Less flexible for very large environments

My Recommendation

There is no universal winner.

  • repmgr is a great choice for teams that want a mature, lightweight solution with minimal infrastructure.
  • Patroni shines in enterprise and cloud-native environments where automation, APIs, and distributed consensus are important.
  • pg_auto_failover sits nicely in the middle. It offers more automation than repmgr while remaining simpler to operate than Patroni.

The best solution depends less on PostgreSQL itself and more on your team’s operational experience. A highly available system that your team understands and can confidently troubleshoot is usually a better choice than a more advanced system that no one is comfortable maintaining.

Conclusion

All three solutions use PostgreSQL’s built-in streaming replication. The real difference lies in how they coordinate failover decisions:

  • repmgr relies on a Witness node to help avoid split brain.
  • Patroni uses a distributed consensus system like etcd to elect a single leader.
  • pg_auto_failover uses a dedicated Monitor node to coordinate promotions.

If you’re just starting with PostgreSQL High Availability, repmgr is often the easiest way to understand the concepts. As your infrastructure grows or moves toward Kubernetes, Patroni becomes a natural next step. If you want an opinionated, easy-to-manage HA solution without the overhead of a distributed key-value store, pg_auto_failover is well worth considering.

I’ve been an Architect, a DevOps, a DataOps, and a DBA. I’m focused on databases, real-time data and streaming technologies. I work with Apache Kafka, RabbitMQ, Elastic Stack and PostgreSQL/MySQL. After hours I love to share my knowledge and experience. I’m founder of DataOps Poland group, it’s an exchange place of experience, concepts and ideas from Data Engineering world.

https://www.linkedin.com/in/tomasz-gintowt/