Pause and resume pgBouncer connections¶
Version added: 3.1.0
You can pause client traffic through pgBouncer without dropping application
connections. Active queries finish, pgBouncer disconnects from the server and queues new client connections until you resume.
When to pause pgBouncer¶
- Database restarts: Restart PostgreSQL without forcing clients to reconnect.
- Planned maintenance: Soften connection errors during a minor upgrade or a restart-required config change. Expect brief latency, not invisible downtime; long pauses can still hit app timeouts.
- Planned switchovers: Pause, change the primary, then resume to avoid a reconnect storm. For emergencies, rely on Patroni failover—PAUSE waits for in-flight work.
- Drain traffic: Stop backend work while client sessions stay open and queued.
How it works¶
- Set
spec.proxy.pgBouncer.pausedtotrueon the Custom Resource. - The Operator connects to each
pgBouncerPod as the internal admin user_crunchypgbounceradminand issuesPAUSE. pgBouncerwaits for current server connections to finish (per your pool mode), disconnects from PostgreSQL, and queues new client queries.- The Operator sets the
PGBouncerPausedcondition toTrue. - Perform the maintenance or switchover.
- Set
pausedback tofalse. The Operator issuesRESUMEand removes thePGBouncerPausedcondition.
If a pgBouncer Pod restarts while paused, a startup probe re-applies PAUSE
so the intended state survives restarts.
Note that with spec.proxy.pgBouncer.paused you control only the connection pooler. To pause the entire cluster, use the cluster pause feature.
Before you start¶
- Check that pgBouncer is enabled with a non-zero replica count.
-
By default, pgBouncer uses the
sessionpooling mode. Insessionmode,PAUSEwaits until clients fully disconnect, which may significantly delay or even block the pause operation. Change the pooling mode from session totransactionorstatementby setting thespec.proxy.pgBouncer.config.global.pool_modeoption in the Custom Resource. -
Keep the paused window short. Queued clients still observe latency, and client-side timeouts still apply.
Pause pgBouncer¶
For the following steps, the cluster name is cluster1. Replace the
<namespace> placeholder with your value.
-
Confirm that pgBouncer Pods are ready:
kubectl get pg cluster1 -n <namespace> \ -o jsonpath='{.status.pgbouncer.ready}/{.status.pgbouncer.size}{"\n"}' -
Set
proxy.pgBouncer.pausedtotrue:kubectl -n <namespace> patch pg cluster1 --type=merge --patch '{ "spec": { "proxy": { "pgBouncer": { "paused": true } } } }'-
Edit the deploy/cr.yaml manifest:
spec: proxy: pgBouncer: paused: true -
Apply the change:
kubectl apply -f deploy/cr.yaml -n <namespace>
-
-
Wait until the Operator reports that pgBouncer is paused:
kubectl get pg cluster1 -n <namespace> \ -o jsonpath='{range .status.conditions[?(@.type=="PGBouncerPaused")]}{.status}{"\n"}{.reason}{"\n"}{.message}{"\n"}{end}'Sample output
True Paused pgbouncer is paused -
Run your maintenance, restart, or planned switchover.
Resume pgBouncer¶
Set proxy.pgBouncer.paused back to false:
kubectl -n <namespace> patch pg cluster1 --type=merge --patch '{
"spec": {
"proxy": {
"pgBouncer": {
"paused": false
}
}
}
}'
Confirm that the PGBouncerPaused condition is gone:
kubectl get pg cluster1 -n <namespace> -o yaml | grep -A3 PGBouncerPaused || true
After resume, queued client queries proceed against PostgreSQL again.
Considerations¶
- Pausing pgBouncer does not pause the PostgreSQL cluster and does not stop Operator reconciliation. Use cluster pause when you need that.
- The Operator manages the
_crunchypgbounceradminuser and stores its password in the pgBouncer Secret underpgbouncer-admin-password. Do not reuse or override this reserved user. See Users. - Do not leave pgBouncer paused longer than your applications can tolerate.
- If pgBouncer Pods are not ready, the Operator cannot complete pause or resume. Check Pod status before you start.
Created: September 9, 2026