A connection pool should bound how much database work an application admits at once and how long callers wait for a connection. Increasing its maximum can move a queue into the database, increase contention, and leave requests slower even though fewer callers are waiting inside the pool.
There is no universal connection count that follows from the number of HTTP workers. Begin with the database's usable capacity, the number of application processes, and how long each operation actually holds a connection.
Count pools across the deployment
Imagine four application replicas. Each has one process and a pool capped at eight connections. Their configured upper bound is 32 connections. If each replica instead runs three independent processes, each creating the same pool, the upper bound becomes 96.
Those are arithmetic examples, not observed capacity results. They show why a setting that looks modest in one process can become a large commitment during autoscaling or a deployment that temporarily overlaps old and new replicas.
PostgreSQL's connection settings describe the server limit and reserved connection slots. An application budget must also account for other services, operators and maintenance. A server permitting another connection does not establish that it can execute another expensive query efficiently.
For each pool, record:
- How many processes create it, including workers and scheduled jobs.
- Its minimum and maximum size.
- The deployment's expected and temporary maximum process count.
- Who else needs connections to the same database.
A database proxy adds another layer. Client connections and database-side server connections may no longer have a one-to-one relationship. Inspect that layer's pooling mode before adding both counts together or assuming it removes all limits.
Measure the time a connection is held
Psycopg's pool guide describes acquiring a connection for a scoped block and returning it afterward. That scope is an operational decision.
Suppose a request holds a database connection while waiting for an unrelated remote API. The pool is occupied even though that request may not be running a query. Enlarging the pool can hide this behavior temporarily while multiplying open transactions or server sessions.
Trace the acquisition, query, transaction completion and release separately. Look for leaked acquisitions, unexpectedly long transactions, lock waits and application work inside the connection scope. Check whether a query is slow before assuming that connection establishment is the bottleneck.
A useful observation table separates three clocks:
| Clock | What it can reveal |
|---|---|
| Connection acquisition wait | Local admission pressure or inability to create usable connections |
| Connection holding time | Query time plus other work performed while holding the resource |
| End-to-end request time | What the caller experiences, including all other dependencies |
A low acquisition wait with poor end-to-end latency is not evidence that a larger pool will help.
Bound the waiting room as well
The Psycopg pool API exposes acquisition timeout and max_waiting alongside size limits. Their exact behavior belongs to that library; do not assume another driver's identically named option means the same thing.
An acquisition timeout bounds waiting for a connection. It is not a statement timeout and does not automatically cap an entire request. A caller may already have consumed much of its deadline before it asks the pool for access.
When admission fails, define the outcome deliberately: reject, defer work or return a retryable response when the operation permits it. Immediate retries from every caller can recreate the same queue. The interaction is covered more generally in timeouts, retries and idempotency.
Change one constraint with evidence
Before raising the maximum, compare pool wait, active database work, query latency, lock waits, CPU and the request error rate under a stated workload. Inspect the number of replicas and processes during the measurement.
If connections sit idle while callers wait, investigate ownership and release. If the database is saturated and queries are slowing, admitting more work may worsen the bottleneck. If connection setup is expensive but database capacity remains available, a different minimum size or reuse policy may be worth testing.
This is the same admission-versus-capacity distinction as our queue backlog guide, applied to a narrower resource. A pool is a control point, not additional database capacity.
No database or load test was run for this article. Psycopg's consulted documentation identifies a development edition; verify settings against the installed release before using an example configuration in production. Treat any proposed new limit as a hypothesis to measure, with the previous limit and rollback conditions recorded.