---
title: "How we scale PgBouncer in ClickHouse Managed Postgres"
description: "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."
url: "https://swe.quest/articles/how-we-scale-pgbouncer-in-clickhouse-managed-postgres-130231ec324c9f46"
canonical: "https://clickhouse.com/blog/pgbouncer-clickhouse-managed-postgres"
source: "ClickHouse"
published: "2026-07-01"
difficulty: "medium"
kind: "Case study"
reading_minutes: 4
tags: ["postgres","performance","load-balancing","linux","scalability"]
---

# How we scale PgBouncer in ClickHouse Managed Postgres

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2026-07-01, 4 min read, Case study. Original: [https://clickhouse.com/blog/pgbouncer-clickhouse-managed-postgres](https://clickhouse.com/blog/pgbouncer-clickhouse-managed-postgres)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Load balancing](https://swe.quest/tags/load-balancing.md) (Infrastructure)
- [Linux](https://swe.quest/tags/linux.md) (Infrastructure)
- [Scaling](https://swe.quest/tags/scalability.md) (Distributed systems)

## Prerequisites

- Postgres connection pooling ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- PgBouncer transaction mode
- Linux socket options ([easy posts on Linux](https://swe.quest/tags/linux.md?difficulty=easy))

## Keywords

PgBouncer, SO\_REUSEPORT, ClickHouse Managed Postgres, pgbench, AWS EC2, CloudWatch

## Related posts

- [PGKeeper: Building the bouncer we needed for Postgres](https://swe.quest/articles/pgkeeper-building-the-bouncer-we-needed-for-postgres-b0a410376e101175.md): Figma · 2026-05-04 · Medium · 19 min read · PostgreSQL, Resilience, Go, Databases, Scaling
  Figma replaced PgBouncer with PGKeeper, a Go service built on PGX that sits between its DBProxy router and each Postgres instance.
- [PgBouncer is now available in Supabase](https://swe.quest/articles/pgbouncer-is-now-available-in-supabase-7611d240679e4c4c.md): Supabase · 2021-04-02 · Medium · 4 min read · PostgreSQL, Serverless, Scaling
  Supabase 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.
- [PostgresBench: A Reproducible Benchmark for Postgres Services](https://swe.quest/articles/postgresbench-a-reproducible-benchmark-for-postgres-services-3a30213211ea6b71.md): ClickHouse · 2026-04-02 · Medium · 9 min read · PostgreSQL, Performance engineering, Storage systems, Cloud platforms
  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.
- [PostgresBench: Measuring the impact of High Availability on Managed Postgres performance](https://swe.quest/articles/postgresbench-measuring-the-impact-of-high-availability-on-managed-postgres-f5f54e9ac5894971.md): ClickHouse · 2026-07-21 · Medium · 7 min read · PostgreSQL, Replication, Performance engineering, Cloud platforms
  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.
- [Supavisor: Scaling Postgres to 1 Million Connections](https://swe.quest/articles/supavisor-scaling-postgres-to-1-million-connections-8585e4b9712f0334.md): Supabase · 2023-08-11 · Medium · 7 min read · PostgreSQL, Elixir & Erlang, Scaling, Multi-tenancy, Performance engineering
  Supavisor is a multi-tenant Postgres connection pooler written in Elixir that Supabase built to replace single-threaded PgBouncer.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
