PostgreSQL Load Balancing, Pooling and Failover Tools

Updated

PostgreSQL load balancing diagram

Three different problems get called “load balancing” and they need different tools:

  • Connection pooling — too many connections for one server. PgBouncer, or Pgpool-II’s pooling.
  • Read load balancing — spreading SELECTs across replicas. Of PgBouncer and Pgpool-II, only Pgpool-II reads the SQL and routes per statement.
  • Failover — promoting a replica when the primary dies. Patroni or pg_auto_failover. Pgpool-II can do it too, with a watchdog.

If PgBouncer’s one CPU core is the limit, PgCat, Odyssey and Supavisor pool the same way and are compared below. PgJDBC and Citus are not load balancers, and the measurements further down show what PgJDBC’s “load balancing” actually does.

Maintenance status, checked on 10 August 2026

All figures from the GitHub API on the date shown; load-balancing-ha-tools.sh re-reads the push dates and repmgr’s compatibility matrix and, given a JDK and PostgreSQL binaries, repeats the PgJDBC experiments below.

project              last release            last push to the repo
Pgpool-II            4.7.2                   2026-08-07
PgBouncer            1.25.2  (2026-05-08)    2026-08-10
Patroni              4.1.4   (2026-07-07)    2026-08-10
HAProxy              3.4.0  (3.5-dev series) 2026-08-10
pg_auto_failover     2.2     (2025-04-03)    2026-08-11
Citus                14.2.0  (2026-08-06)    2026-08-10
pgJDBC               42.7.13 (2026-07-06)    2026-08-03
repmgr               5.5.0   (2024-11-22)    last commit on master 2025-04-17

repmgr is the one to think twice about. It is not archived, and its latest release is still 5.5.0 (2024-11-22). The last-commit date in the table was read on 10 August 2026; on 24 October 2026 the newest commit on master is from 2 October 2026, “add PG 18 to README.md and compatibility matrix (#921)”, and the compatibility matrix on master lists repmgr 5.5 as supporting “13, 14, 15, 16, 17, 18”. The matrix published at repmgr.org/docs/current still lists “13, 14, 15, 16, 17” on 24 October 2026, so PostgreSQL 18 is documented as supported on master and not yet on the published page. pg_auto_failover moved from the citusdata organisation to hapostgres; the old URL still redirects, and the repository is active even though 2.2 is over a year old.

PgJDBC is not a load balancer, measured

Run on 10 August 2026 with pgjdbc 42.7.13 on OpenJDK 26.0.2 against a PostgreSQL 17.10 primary and its streaming standby. With loadBalanceHosts=true, 40 connections of 3 queries each split 15 to the primary (exactly 45 queries) and 25 to the standby (75). With the default false, all 40 went to the first host in the URL. The choice is made once per connection; no statement is ever routed. That is a failover convenience, not load balancing.

Thirty INSERTs over loadBalanceHosts=true: 11 succeeded and 19 failed with “ERROR: cannot execute INSERT in a read-only transaction”. Four repeats of the identical script lost 11, 15, 16 and 21 writes out of 30. The fix is targetServerType: primary put 20 of 20 connections on the primary, and preferSecondary put 20 of 20 on the standby. Route reads and writes yourself in the application. PgJDBC’s own PGPoolingDataSource is deprecated; its Javadoc points to “a fully featured connection pool like HikariCP, vibur-dbcp, commons-dbcp, c3p0, etc.”

Citus is not a load balancer and does not cost money

Citus shards tables across worker nodes; it changes where your data lives, not where a query is sent. It is free software: the GitHub API reports its licence as AGPL-3.0.

PgBouncer alternatives compared: PgCat, Odyssey, Supavisor and Pgpool-II

Read from each project’s documentation on 2026-10-11 at the versions shown, plus PgCat and Supavisor config and source. The table comes from those docs, not from a deployment; I ran PgBouncer 1.25.2 and Pgpool-II 4.7.2 side by side, and the results are in PgBouncer vs Pgpool-II.

Pooler (docs version) Threading Prepared statements, transaction pooling Read load balancing Failover
PgBouncer 1.26.0 One thread, one core per instance; so_reuseport runs several Since 1.21.0, with max_prepared_statements above 0 Round-robin per new connection over DNS results or a host list (load_balance_hosts) No failover setting in the config reference
Pgpool-II 4.7.3 Child processes (num_init_children) No limit in the Restrictions chapter (untested) Reads to any node, writes to the primary; fixed per session unless statement_level_load_balance Automatic failover; watchdog for Pgpool-II itself
PgCat v1.2.0 Multi-threaded (Tokio) Yes in transaction mode if prepared_statements_cache_size is above 0 (default 0); README says no Random or least open connections Bans an unreachable replica for ban_time (60 s default); never the primary
Odyssey v1.5.2 Multi-threaded worker threads Yes, with pool_reserve_prepared_statement yes Random host from the storage list (since 1.4.1); target_session_attrs picks read-only or read-write read-write picks the writable host; no promotion in the pages I read
Supavisor v2.9.13 Not stated in README or FAQ Yes with NAMED_PREPARED_STATEMENTS_ENABLED (default false, since v2.7.0); FAQ says session only Queries can be balanced across read replicas Buffers connections across restarts or failovers; separate from Postgres HA

GitHub API, 2026-10-11: Odyssey v1.5.2 was released 2026-09-13, Supavisor v2.9.13 on 2026-09-10, and PgCat’s last commit on main was 2025-02-27. PgBouncer 1.26.0 (2026-09-23) and Pgpool-II 4.7.3 are newer than the 10 August table above.

How to choose

If the problem is connection count, start with PgBouncer, and keep it until one core is saturated: so_reuseport adds cores before you need to change tools. I ran PgBouncer 1.25.2 and Pgpool-II 4.7.2 side by side against one PostgreSQL 17.11 cluster in PgBouncer vs Pgpool-II. Odyssey adds threads and documents prepared statements in transaction mode; PgCat adds threads and read balancing; Supavisor targets many tenants. If you need SELECTs spread over replicas without changing the application, Pgpool-II does it; see how its load balancing actually behaves, including the settings that silently disable it. For “what happens when the primary dies”, use Patroni or pg_auto_failover, with HAProxy in front for the client-facing address; HAProxy alone balances TCP connections and has no idea which backend is writable.

What was not tested

Only PgJDBC was exercised here, plus the Pgpool-II measurements on the Pgpool-II load balancing page linked under “How to choose”. PgBouncer is measured on the PgBouncer vs Pgpool-II page, not on this one. Patroni, repmgr, pg_auto_failover, HAProxy, PgCat, Odyssey and Supavisor were not deployed (this machine is macOS, with no Linux host). Dates and the pooler table come from project repositories and docs; “How to choose” is judgement, not measurement.

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.