PgBouncer + Patroni vs. PgBouncer Alone: How to Route PostgreSQL Writes Safely

A practical comparison of PostgreSQL HA architectures where PgBouncer is used either as a role detector or purely as a connection pooler

PgBouncer vs. Patroni (via HAProxy): Choosing the Right Health-Check Strategy for PostgreSQL Failover

High-availability in PostgreSQL depends heavily on how your load balancer detects the active primary. Two common approaches are:

  • PgBouncer with SQL-based health-checks
  • Patroni’s REST-based health-checks through HAProxy

This article compares both, focusing on reliability, operational complexity, and real-world HA behavior.

Why Health-Checks Matter

Most failover outages happen because the load balancer misidentifies the primary. Poor checks lead to:

  • read/write errors
  • split-brain
  • slow failovers
  • cluster instability

Approach 1: PgBouncer Health-Checks

PgBouncer executes queries such as SELECT pg_is_in_recovery() to detect the primary.

Pros

  • Lightweight and extremely fast
  • Works without Patroni
  • Reduces PostgreSQL connection load
  • Simple architecture

Cons

  • Cannot coordinate failover
  • Cannot reliably protect from split-brain
  • Limited insight into cluster state
  • Requires custom HAProxy checks

Approach 2: Patroni + HAProxy Health-Checks

Patroni exposes a REST API that HAProxy queries to identify the leader.

Pros

  • Perfect primary identification
  • Automatic and coordinated failover
  • Split-brain protection
  • Easy read/write routing
  • Ideal for multi-replica clusters

Cons

  • More components (Patroni + HAProxy + DCS)
  • Requires operational expertise
  • Needs API exposure

Comparison Table

FeaturePgBouncerPatroni + HAProxy
Primary detectionNoYes
Automatic failoverNoYes
Split-brain protectionNoYes
SimplicityHighMedium
Production-grade HAMediumHigh

When to Use Each

Use PgBouncer if:

  • You only need connection pooling
  • Failover is manual
  • Architecture is simple
  • You want minimal overhead

Use Patroni with HAProxy if:

  • You need real high-availability
  • Failover must be automatic
  • Cluster consistency is critical
  • You run multiple replicas
  • Downtime is unacceptable

Final Thoughts

PgBouncer is excellent for pooling, but it is not a primary-detection or failover component.
For serious HA, Patroni + HAProxy remains the most reliable approach.

If you want help designing a production-ready PostgreSQL HA architecture, contact Sysroot.io — this is exactly what we specialize in.

Published on: December 13, 2025
Tags: postgresql, high-availability, infrastructure, database, devops