---
title: "Pool database connections · Agent Wranglers"
url: https://agentwranglers.se/playbook/data/operations/connection-pooling
updated: 2026-10-20
licence: "All rights reserved"
---

# Pool database connections

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Recommended
- Chapter: [Operations](https://agentwranglers.se/playbook/data/operations)
- Rule: Reuse a small, fixed pool of connections instead of opening one per request.
- How: 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.
- 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`.

- Next: [Set time limits on every query](https://agentwranglers.se/playbook/data/operations/query-timeouts)
- [Operations](https://agentwranglers.se/playbook/data/operations)
