SKILL.md
Database Connection Pooler
Overview
Configure and optimize database connection pooling using external poolers (PgBouncer, ProxySQL, Odyssey) and application-level pool settings to prevent connection exhaustion, reduce connection overhead, and improve database throughput.
Prerequisites
psqlormysqlCLI for querying connection metrics- Access to database configuration files (
postgresql.conf,my.cnf) formax_connectionssettings - PgBouncer, ProxySQL, or Odyssey installed if using external pooling
- Application connection pool settings accessible (database URL, pool size parameters)
- Server CPU core count and available memory for pool sizing calculations
Instructions
-
Audit current connection usage by querying active connections:
- PostgreSQL:
SELECT count(*) AS total, state, usename FROM pg_stat_activity GROUP BY state, usename ORDER BY total DESC - MySQL:
SHOW STATUS LIKE 'Threads_connected'andSHOW PROCESSLIST - Compare against
max_connectionssetting to determine headroom
- PostgreSQL:
-
Calculate the optimal pool size using the formula:
pool_size = (core_count * 2) + effective_spindle_count. For SSD-backed databases, usecore_count * 2 + 1. A 4-core server with SSD storage should have a pool size of approximately 9. This formula applies per application instance. -
Configure application-level connection pool parameters:
- minimumIdle: Set to 2-5 for low-traffic periods (avoids cold-start latency)
- maximumPoolSize: Set using the formula from step 2
- connectionTimeout: 5-10 seconds (fail fast rather than queue indefinitely)
- idleTimeout: 10-30 minutes (release idle connections back to pool)
