Set PgBouncer pool size from a per-pool connection budget, then verify it against PostgreSQL’s usable connection capacity and representative load; do not choose it from client count or a fixed rule. This approach suits teams that can observe both pool wait and database pressure before changing production settings.
For PostgreSQL DBAs, the task is to reconcile PgBouncer limits with the database’s available connections.
For backend engineers, it is to trace waits after application instances or workers change.
For SaaS leads, it is to turn measured demand into a defensible 2027 database and server plan.
Start with the connection inventory
A client count is not a server connection budget. Applications may create connections through several paths, and those paths do not all pass through PgBouncer. Record them separately before changing pool settings.
Include application instances, worker processes, scheduled jobs, deployment overlap, monitoring, migration tools, administrative access, and any service that connects directly to PostgreSQL. For each application path, note the database user and database name it uses. Those identities matter because PgBouncer creates pools by user and database, rather than treating every client as one shared pool. Confirm the pool scope in the PgBouncer configuration reference.
| Connection path | What to count | Budget treatment |
|---|---|---|
| Application through PgBouncer | Potential client connections by application, user, and database | Count client demand separately from PgBouncer server connections |
| Background workers through PgBouncer | Worker processes and their connection behavior | Include in the pool demand for the relevant user-database pair |
| Direct database access | Migration, monitoring, administration, and other bypass connections | Reserve PostgreSQL capacity outside the PgBouncer pool budget |
| Deployment overlap | Old and new application processes that may coexist during rollout | Include the overlap that your deployment procedure can create |
Use application configuration, deployment manifests, process counts, and connection logs to make the inventory reproducible. A list copied from a diagram is not enough: it should show which process opens connections, which credentials it uses, where it connects, and whether it connects through PgBouncer.
Does default_pool_size apply to every connection pool as one shared total? No. It is a per-pool server-connection limit, not a single global total shared across all user-database pools. The total possible server connections can therefore grow as the number of active pools grows. Check the behavior against the PgBouncer version and configuration in use; do not multiply a single setting by an assumed pool count without verifying which pools are actually created.
Two common gaps distort the inventory. First, rolling deployments can temporarily leave both old and new application processes active. Second, operators often forget direct paths used only during migration or maintenance. A pool may appear correctly sized while the direct connections consume the remaining PostgreSQL capacity.
Build one connection budget before editing settings
Calculate the PostgreSQL budget first. Start with max_connections, then account for reserved connection slots and connections needed by administration, monitoring, migrations, and other direct clients. PostgreSQL documents max_connections, reserved_connections, and superuser_reserved_connections as distinct connection settings; the privileges and slots they protect differ. Use the PostgreSQL connection settings documentation to check the exact behavior for the deployed version.
A useful worksheet keeps three quantities separate:
- PostgreSQL capacity: the configured connection ceiling and the slots reserved for privileged access.
- PgBouncer server-connection demand: the sum of the limits for the user-database pools that can be active.
- Non-pooled demand: direct connections that must remain available for normal operations and recovery work.
Do not treat the PostgreSQL connection ceiling as a target that every pool can consume. The operational budget must leave room for the direct paths and reserved access identified in the inventory. Apply the calculation per PostgreSQL instance. If the application can connect to more than one database server, maintain a separate budget for each one.
| PgBouncer control | What it limits | How it affects the budget |
|---|---|---|
default_pool_size |
Server connections for a pool using the default setting | Can apply to multiple user-database pools; add each relevant pool when estimating the possible total |
pool_size |
Server connections for a specifically configured pool | Use when a particular user-database pair needs a distinct ceiling |
reserve_pool_size |
Additional server connections available to a pool under the configured reserve conditions | Include the possible reserve capacity when checking the upper bound |
max_db_connections |
Server connections to a database through PgBouncer | Can cap the combined pool demand for that database |
max_client_conn |
Client connections accepted by PgBouncer | Limits the client side; it is not a PostgreSQL server-connection budget |
These controls govern different things. A large max_client_conn does not mean PostgreSQL will open that many server connections, and a safe default_pool_size does not prove the aggregate is safe when many pools exist. PgBouncer also documents operating-system file descriptor limits and related constraints. Review those alongside the connection settings in the official configuration reference.
How should several application users and databases be combined? Build a row for each active user-database pool, record its configured pool ceiling, and sum the possible server connections. Then compare that sum with the PostgreSQL budget after reserved and direct connections are accounted for. Apply max_db_connections where it provides a database-level cap, but do not assume it replaces the per-pool calculation.
Keep the worksheet reviewable. Include the configuration source, the application owner, the expected pool identity, and whether the connection is direct or pooled. If a pool is created dynamically or has an unclear owner, resolve that before treating its capacity as spare.
Step through configuration without guessing
Make changes in a controlled order. The goal is to constrain both client acceptance and server-side demand without creating an unobserved bottleneck.
Step 1: Record the current state
Save the PgBouncer configuration, the PostgreSQL connection settings, and the application connection settings. Record current client counts, server connections, pool waits, database activity, and the deployment state. Keep a rollback copy of every file changed.
Step 2: Map pool identities
List the database and user combinations that PgBouncer actually serves. Match each combination to application services and jobs. Check whether different services share credentials; if they do, their demand may land in the same pool rather than in separate pools.
Step 3: Set per-pool ceilings
Use default_pool_size for the baseline only when the same limit is appropriate across the pools that inherit it. Use a specific pool_size where a known workload needs a different ceiling. Check reserve_pool_size and its activation conditions rather than treating reserve capacity as free headroom.
Step 4: Add aggregate and client-side limits
Use max_db_connections when the total server connections to a database need a cap. Set max_client_conn according to client-side demand and PgBouncer’s process and file-descriptor constraints. These limits protect different resources; neither substitutes for the PostgreSQL connection budget. PgBouncer’s usage documentation describes its administrative interface and runtime statistics, which can help verify the configured pools.
Step 5: Check the host boundary
Review the operating-system limits that constrain file descriptors and process resources. PgBouncer may accept many clients while still being unable to maintain the expected sockets if the host limits are too low. PostgreSQL also has kernel and resource considerations; consult its kernel resource guidance rather than assuming the connection parameter alone defines safe capacity.
A connection ceiling is a guardrail, not a performance target. If the database is already saturated, raising the pool limit can increase contention without resolving the cause.
Validate the pool under representative load
Test outside production first. Reproduce the application’s connection pattern, not just a simple query loop. Include the mix of short requests, long-running work, background jobs, and transaction behavior that can hold server connections.
Increase load in controlled increments. At each stage, capture client wait time, the number of server connections in use and available, PostgreSQL connection counts, query activity, CPU, memory, and storage behavior. Keep the test configuration and workload consistent so that a before-and-after comparison is meaningful.
PgBouncer’s administrative statistics show pool activity and waiting clients. PostgreSQL’s monitoring views provide database-side activity and connection information. Use both sides of the boundary: PgBouncer can show that clients are waiting, while PostgreSQL can show whether the database is busy, idle, or occupied by long-running work. The PgBouncer usage guide and PostgreSQL monitoring documentation describe the relevant interfaces and views.
The pool is full, but PostgreSQL CPU is not high. What should be checked first? Check for long transactions, sessions waiting on locks or I/O, and uneven demand across user-database pools. Low CPU alone does not show that the database has spare connection capacity. A connection can remain occupied while its session waits, and one pool can be exhausted even when another pool has unused capacity. Compare the pool statistics with PostgreSQL activity before increasing the limit.
Use a simple decision sequence:
- If clients wait and the relevant pool is at its ceiling, check whether that pool’s sessions are doing useful work or are held by long transactions.
- If PostgreSQL has connection headroom and the workload is not resource-saturated, increase the affected pool limit cautiously and repeat the same test.
- If database resources are saturated, investigate query behavior, locks, memory pressure, and storage instead of increasing the pool by default.
- If direct connections consume the remaining budget, revise the connection plan before changing PgBouncer.
- If client waits disappear but database pressure rises, revert the change and test a lower limit.
PostgreSQL’s resource settings can affect how concurrent work competes for memory and other resources. Review the resource consumption documentation while interpreting a test. Do not infer a safe pool size from CPU alone.
Put the result into the 2027 capacity plan
A useful procurement request contains the evidence behind the requirement, not just a desired connection count. Summarize the active pool identities, calculated server-connection ceiling, direct-access allowance, observed waits, database resource state, and the test conditions that produced them. Record the point at which the database became constrained, if the test established one. If it did not, mark that uncertainty rather than presenting an untested ceiling as a capacity guarantee.
Connection demand by itself does not determine a server configuration. Use the test to identify what resource needs review: memory pressure, storage behavior, CPU contention, or connection management. The database server configuration guide can help turn those observations into a broader resource brief. Then check CloudDDR’s bare metal pricing and available configurations against the workload and the team’s operating model. Confirm the current product details directly; do not infer a server specification or price from a connection-pool calculation.
A dedicated AMD bare metal server can be a better fit when a database workload needs exclusive hardware resources and the team is prepared to manage PostgreSQL, patching, monitoring, backups, and recovery. It does not automatically fix slow queries, remove connection contention, or protect data. A managed database may remain preferable when its operational support and integrated recovery features outweigh its cost or configuration limits.
Before treating a self-managed server as ready, plan data protection separately. PostgreSQL’s continuous archiving and point-in-time recovery documentation explains the building blocks for recovery from archived WAL. Keep backups outside the database host and test restoration; server rental is not a backup plan.
If shared instances or managed database tiers make CPU allocation, storage behavior, or long-term costs difficult to control, compare those constraints with an exclusive machine only after the load test confirms the need. If the workload is light, temporary, or highly elastic, a shared or managed option may still be the better decision. For a stable workload that needs dedicated resources and a team-owned PostgreSQL stack, review CloudDDR’s current configurations against the measured budget—not as a substitute for connection planning, but as the next step in it.
Dedicated AMD EPYC 7543P server, from $447/month.