How we scale PgBouncer in ClickHouse Managed Postgres
Because PgBouncer is single-threaded, ClickHouse Managed Postgres runs a fleet of PgBouncer processes sized to the core count, all binding one port via so_reuseport so the kernel load-balances connections behind a single endpoint. Peering between processes forwards cancel requests that land on the wrong process, and max_client_conn and max_db_connections are divided across the fleet so Postgres is never oversubscribed. On a 16-vCPU c7i.4xlarge with pgbench select-only load, a single process peaked near 87k TPS and degraded to 77k at 256 clients while pinned at one core. A 16-process fleet reached about 336k TPS (roughly 4x) using about 8 cores. At very low concurrency the single process is marginally faster, so the fleet pays off only once the pooler becomes the bottleneck.
Related posts
- PGKeeper: Building the bouncer we needed for Postgres
Figma mediumAdept
Figma replaced PgBouncer with PGKeeper, a Go service built on PGX that sits between its DBProxy router and each Postgres instance. Clients reach it over gRPC with per-query metadata such as traffic tier and request source. PgBouncer was ruled out for its single-threaded scaling ceiling, lack of prioritization and backpressure, and weak protection against connection churn. Pooling inside DBProxy was ruled out because hundreds of replicas cannot share a ~100-connection pool, and PGCat would have required a fork. PGKeeper token-bucket rate-limits both connection creation and teardown, warms pools before taking traffic, and avoids churn with bounded result draining, automatic ROLLBACK, and context cancellation via pg_cancel_backend plus SELECT 1. Its priority-based semaphore admission control uses CoDel to shed stale lower-priority work during concurrency spikes.
- PgBouncer is now available in Supabase
Supabase mediumAdeptSupabase now bundles PgBouncer, co-located on the same server as each new project's Postgres, so serverless functions that open a connection per request don't overwhelm the database. The pooler keeps a fixed set of connections open, currently a pool size of 15, and queues clients when all are busy rather than raising Postgres's connection limit. Three pool modes are available: session (full feature support), transaction (recommended for serverless, but no session features like prepared statements) and statement (no multi-statement transactions, suited to autocommit). Pooling applies to new projects only.
- PostgresBench: A Reproducible Benchmark for Postgres Services
ClickHouse mediumAdept
PostgresBench is an open, reproducible benchmark for managed Postgres services built on pgbench's TPC-B-like workload (256 clients, 16 threads, 10-minute runs, three runs each) at ~100 GB and ~500 GB scale factors, with default configs, HA disabled and all services in us-east-2. In the first cohort, ClickHouse's NVMe-backed managed Postgres reached about 28.7K TPS on 16 vCPU/64 GB at 100 GB, versus 14.8K for Crunchy Bridge, 12.6K for Aurora, 8.6K for Neon and 8.1K for RDS, and held about 26K TPS at 500 GB. ClickHouse attributes the lead to co-located local NVMe storage, which avoids network round trips on every fsync and WAL commit in write-heavy workloads. Scripts and raw JSON results are on GitHub for verification and community submissions, though the vendor-run setup and absence of pricing comparisons are worth weighing.
- PostgresBench: Measuring the impact of High Availability on Managed Postgres performance
ClickHouse mediumAdept
PostgresBench now measures the performance cost of high-availability configurations across managed Postgres services, comparing shared-nothing designs (ClickHouse Managed Postgres, RDS, Crunchy Bridge) that use streaming standbys with shared-storage forks (Aurora, Neon) that replicate WAL to a storage layer. On a 16 vCPU/64 GB instance with a 500 GB dataset, ClickHouse's NVMe-backed service dropped to 94% of single-node TPS with one async standby and 79% with two synchronous quorum standbys, with p99 latency rising 1.8x and 2.5x. RDS throughput was roughly flat, but its p99 rose to 1.7x with one sync standby and 6.3x (817 ms) with a two-standby quorum cluster. The vendor-run results claim 2-4x throughput advantages for ClickHouse over the other services at matched compute and comparable durability.
- Supavisor: Scaling Postgres to 1 Million Connections
Supabase mediumAdeptSupavisor is a multi-tenant Postgres connection pooler written in Elixir that Supabase built to replace single-threaded PgBouncer. In benchmarks one 16-core instance held 250,000 client connections over a 400-connection database pool, and a 64-core instance held 500,000. Two 64-core nodes, one connected to the database and one relaying through it, held 1,003,200 connections at 20,000 QPS. Median query latency was under 2ms at 5,000 QPS, but running the pooler as a separate cluster adds about 2ms per query compared with co-located PgBouncer, in exchange for not consuming the database server's CPU and RAM.