← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

Database Connection Pooling

concurrency Intermediate
debt(d7/e5/b5/t5)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The term's detection_hints show automated=no, and the code_pattern 'new PDO\(|pg_connect' only detects connection creation, not whether pooling is properly configured. Connection exhaustion issues typically manifest only under production load, requiring runtime testing or careful review of infrastructure setup. No automated tools from detection_hints can catch missing PgBouncer/ProxySQL configuration.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix mentions adding PgBouncer or ProxySQL in production and configuring pool sizes - this involves infrastructure changes, configuration files, and potentially adjusting application connection parameters. While setting ATTR_PERSISTENT is a one-liner, the full solution for production pooling requires deployment configuration, not just code changes.

b5 Burden Structural debt — long-term weight of choosing wrong

Closest to 'persistent productivity tax' (b5). The term applies_to web, cli, and queue-worker contexts, meaning the pooling strategy affects multiple execution environments. The choice of pooler (PgBouncer vs ProxySQL) and pool sizing becomes a system-wide concern that shapes deployment architecture and influences how all database-touching code behaves under load. Not quite 'defines the system's shape' (b9) but definitely more than localized.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap (a documented gotcha most devs eventually learn)' (t5). The misconception field explicitly states the trap: 'PHP persistent connections (ATTR_PERSISTENT) are the same as a connection pool.' This is a documented gotcha where developers think they have pooling via ATTR_PERSISTENT when they actually just have per-process connection reuse. Common mistake of 'persistent connections with dirty state' reinforces this trap.

About DEBT scoring →

TL;DR

Connection pooling reuses a fixed set of database connections across requests — eliminating the 50–200ms connection overhead on every request and limiting DB connection count.

Explanation

Opening a DB connection is expensive (TCP handshake, authentication, SSL). Pooling: maintain N open connections, hand them out per request, return after use. PHP-FPM: each worker maintains its own persistent connection (PDO with ATTR_PERSISTENT). PgBouncer (PostgreSQL), ProxySQL (MySQL): external poolers between app and DB. Benefits: lower latency, limited max connections to DB (DB has hard limits). Pitfalls: persistent connections in PHP-FPM can carry state (transactions, temp tables) — always clean up. Swoole: built-in connection pool per coroutine pool. Laravel Octane: persistent PDO connections per worker.

Common Misconception

PHP persistent connections (ATTR_PERSISTENT) are the same as a connection pool — persistent connections just reuse the same connection per PHP process; a pool manages multiple connections across processes.

Why It Matters

Without pooling, a DB with 100 connections limit is exhausted by 100 concurrent PHP-FPM workers — connection poolers let thousands of workers share a limited connection count.

Common Mistakes

  • Not using PgBouncer/ProxySQL in production — DB exhausts connections under load.
  • Persistent connections with dirty state (uncommitted transactions left on connection).
  • Forgetting to return connections to Swoole pool in finally block.

Code Examples

✗ Vulnerable
// New connection per request — 100 workers = 100 connections:
$pdo = new PDO($dsn, $user, $pass); // Fresh connection each time
✓ Fixed
// PHP-FPM persistent:
$pdo = new PDO($dsn, $user, $pass, [PDO::ATTR_PERSISTENT => true]);

// External pooler config (PgBouncer):
# pgbouncer.ini:
# max_client_conn = 1000  (app connections)
# pool_size = 20           (DB connections)

Added 23 Mar 2026
Views 32
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
2 pings F 0 pings S 0 pings S 1 ping M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 2 pings F 0 pings S
No pings yet today
Amazonbot 1 Perplexity 1
Amazonbot 10 Perplexity 8 Unknown AI 3 Ahrefs 2 ChatGPT 1 Meta AI 1 Google 1
crawler 25 pre-tracking 1
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Medium
⚡ Quick Fix
Use ATTR_PERSISTENT for PHP-FPM. Add PgBouncer (PostgreSQL) or ProxySQL (MySQL) in production. Set pool size based on DB max_connections and worker count.
📦 Applies To
web cli queue-worker
🔗 Prerequisites
🔍 Detection Hints
new PDO\(|pg_connect
Auto-detectable: ✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Medium Context: File

✓ schema.org compliant