Agent Wranglers

Operations Recommended

Pool database connections

Reuse a small, fixed pool of connections instead of opening one per request.

How to do it

Use the driver's pool, or a pooler such as PgBouncer when many app servers share a database. Keep the pool size times the number of app processes below the database's connection limit. Serverless functions need an external pooler, because each copy would open its own connections. A pooler in transaction mode hands each transaction a different connection. Then session state such as SET, advisory locks and LISTEN breaks, so use SET LOCAL inside the transaction.

How to check

Under a load test, the app's open connections stay at or below the pool size times the number of app processes.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers data playbook: https://agentwranglers.se/playbook/data/operations/connection-pooling.