Skip to main content
Every Postgres connection consumes a server process and shared memory. At high connection counts — common in microservice architectures and serverless workloads — this overhead degrades query throughput and can exhaust server resources entirely. pgBouncer sits in front of PostgreSQL and multiplexes application connections onto a much smaller pool of real server connections, dramatically reducing overhead without changing your application’s connection string. PGO integrates pgBouncer natively. Add a single proxy.pgBouncer section to your PostgresCluster spec and the operator manages the Deployment, Service, TLS certificates, and user authentication automatically.

Enable pgBouncer

The minimal configuration is an empty pgBouncer object. This starts one pgBouncer pod in transaction pooling mode using PGO defaults.
Once the cluster reconciles, verify the pgBouncer pod is running:

Configure pool size and mode

Use spec.proxy.pgBouncer.config.global to set any pgBouncer configuration parameter. Key settings include pool_mode, max_client_conn, and default_pool_size.
Changes to config.global are reloaded automatically without restarting pgBouncer. However, invalid configuration values can put pgBouncer into an unusable state, so validate your settings before applying.

Scale pgBouncer replicas

For high-traffic clusters, run multiple pgBouncer pods behind the Kubernetes Service. Each pod maintains its own connection pools independently.

Database routing

By default, pgBouncer routes all connections through a wildcard (*) entry that targets the primary PostgreSQL instance. Use config.databases to define explicit routing rules with libpq-style connection strings.

Per-user settings

config.users lets you apply pgBouncer settings for specific database users, such as overriding the pool size or pool mode.

Expose pgBouncer externally

By default the pgBouncer Service is ClusterIP. Change spec.proxy.pgBouncer.service.type to expose it via a LoadBalancer or NodePort.

Retrieve the connection endpoint

1

Find the pgBouncer Service

2

Get the pgBouncer connection secret

PGO writes pgBouncer connection details into the per-user secret alongside the direct Postgres connection string. The key pgbouncer-uri contains a connection URI pointing at the pgBouncer Service.
3

Connect through pgBouncer

Use the pgbouncer-uri in your application. The URI points to the pgBouncer Service on port 5432 (the default), using the same credentials as the direct connection.

Direct Postgres vs. pgBouncer

Use the right endpoint for each workload type:
pgBouncer in transaction pooling mode does not support SET statements that persist across transactions, server-side prepared statements (unless server_reset_query is configured), or LISTEN/NOTIFY. Use session pooling mode or a direct connection for these use cases.

Custom TLS for pgBouncer

To supply your own TLS certificate for the pgBouncer endpoint, reference a Secret projection containing tls.crt, tls.key, and ca.crt:

Create a cluster

Configure instances, storage, and Postgres parameters.

High availability

Run multiple replicas with automatic failover via Patroni.

TLS

Manage certificates for encrypted Postgres and pgBouncer connections.

Custom Resource Reference

Full field reference for spec.proxy.pgBouncer.