Four trillion messages a month, over 600,000 open connections, and more than 200 million authentications per day. At Datadog, a single proxy layer handles that load in front of thousands of PostgreSQL hosts. They used to run a mix of PgBouncer, HAProxy, and Envoy. On December 1, 2026, they open-sourced its Apache-2.0 replacement in Go: PG Proxy.
Why PostgreSQL needs a pooler and where PgBouncer falls short
Every PostgreSQL connection spawns a separate OS process, so keeping thousands of idle sessions open is expensive. A connection pooler shares a small pool of backend connections among many clients. In transaction pooling mode, a client holds a slot only for the duration of a transaction and returns it on COMMIT or ROLLBACK.
Classic PgBouncer is single-threaded. To use multiple CPU cores, teams had to run multiple processes and recalculate max_connections. Combining it with HAProxy and Envoy split up configs and broke tracing, while cluster migrations stalled as teams updated DNS and redeployed services.
PG Proxy combines those roles in one Go process. It scales across all CPU cores (over 1,000 messages/sec per core) and separates logical database names from physical clusters.
Standalone binary and Go library with hooks
As a drop-in PgBouncer replacement, you run cmd/pg-proxy with a YAML or JSON config. TLS, SCRAM-SHA-256, and export to OpenTelemetry or Datadog Agent work out of the box.
# Physical DB, cluster, and logical name
databases:
- name: orders-primary
host: orders-db.example.com
dbname: orders
username: orders_backend
password_file: /run/secrets/db_password
sslmode: verify-full
clusters: { orders: { primary: orders-primary } }
logical_databases: { orders: { cluster: orders } }
# TLS is required when using passwords
proxy:
listener_address: "0.0.0.0:15432"
password_auth_enabled: true
tls_required: true
tls_cert_file: "/etc/pg-proxy/server.crt"
tls_key_file: "/etc/pg-proxy/server.key"
users:
- static_credentials:
username: alice
password_file: /run/secrets/alice_password
databases: [orders]
You validate configs with ./bin/pg-proxy -config proxy.yaml -validate-config. With pg_proxy.dynamic_routing=true, simple SELECT queries and BEGIN READ ONLY route to replicas in read_clusters, while SELECT ... FOR UPDATE stays on the primary.
The second option is embedding PG Proxy as a Go library with custom auth, quotas, and telemetry.
// Initialize OpenTelemetry before starting the proxy
restore := pgproxy.Bootstrap(pgproxy.Dependencies{
Tracer: pgotel.NewTracer(tp.Tracer("pg-proxy")),
Metrics: pgotel.NewMetrics(mp.Meter("pg-proxy")),
LogHandler: pgotel.NewLogHandler(lp.Logger("pg-proxy")),
})
defer restore()
// Server with a custom auth hook
srv, err := server.NewServer(ctx, server.Config{
ListenAddress: "0.0.0.0:15432",
TLSConfig: tlsCfg,
RequireTLS: true,
// Hook checks client token and returns service name
Authenticate: verifyServiceToken,
Runtime: server.RuntimeConfig{
Inventory: inventory,
Settings: topology.RuntimeConfig{
// At 0, responses flush to the socket one by one
PostgresMessageBufferSize:
topology.DefaultPostgresMessageBufferSize,
},
},
})
Watch out for a subtle trap in Runtime: PostgresMessageBufferSize defaults to 0. Without topology.DefaultPostgresMessageBufferSize (10,240), the library flushes every row packet one by one, slowing down large queries.
Switching cost: PG Proxy vs PgBouncer and alternatives
| Tool | Stack | Pooling | Best fit |
|---|---|---|---|
| PG Proxy | Go (bin + SDK) | Transaction | Auth/OTel hooks |
| PgBouncer | C (1 thread) | Session/tx/stmt | Lightweight pooler |
| Odyssey | C (multi-thread) | Session/tx | Per-DB rules |
| PgDog | Rust | Session/tx | Sharding |
| Pgpool-II | C | Connection reuse | HA and failover |
Per the PG Proxy docs, only transaction pooling is supported. Temporary tables, LISTEN/NOTIFY, and session advisory locks won't work.
Be careful with SIGHUP: instead of hot-reloading, pg-proxy exits without draining, so roll updates using SIGTERM and pod rotation. Building requires Go 1.26+ and CGO (pg_query_go). There is no SCRAM-SHA-256-PLUS, no post-login message size limit, and no read-after-write consistency on replicas. The Go API is still changing, and Datadog kept JWT auth and autoscaling internal.
For a couple of databases with a 'set and forget' setup, PgBouncer is simpler. PG Proxy pays off for Go and Kubernetes teams that want a programmable gateway across dozens of clusters with custom auth and tracing.


