optimizing-database-connection-pooling
БесплатноЗапускает вложенные скриптыНе проверенProcess use when you need to work with connection management. This skill provides connection pooling and management with comprehensive guidance and…
от jeremylongshore★ 2 961 звезда на GitHubОб этом скилле
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)
- maxLifetime: 30 minutes (prevent stale connections from accumulating)
- leakDetectionThreshold: 60 seconds (log warning for connections held too long)
For PostgreSQL with many application instances, deploy PgBouncer in transaction pooling mode:
- Set
pool_mode = transactionto multiplex connections (one backend connection serves many clients between transactions) - Set
default_pool_size = 20andmax_client_conn = 1000 - Configure
server_idle_timeout = 600to close unused backend connections - Set
server_lifetime = 3600to periodically refresh connections
- Set
For MySQL with many application instances, deploy ProxySQL:
- Configure connection multiplexing in
mysql_serverstable - Set
max_connectionsper backend server - Configure query rules for read/write splitting to replicas
- Enable connection pooling with
free_connections_pct = 10
- Configure connection multiplexing in
Set
max_connectionsin the database server based on available memory. Each PostgreSQL connection uses approximately 5-10MB of memory. For a server with 8GB RAM:max_connections = (8192MB - 2048MB_for_OS - 2048MB_shared_buffers) / 10MB = ~400. For MySQL, each thread uses approximately 1-4MB.Implement connection health checks. Configure the pool to validate connections before lending (
testOnBorroworvalidation-query). Use a lightweight query:SELECT 1for MySQL or a simple query for PostgreSQL. Set validation interval to avoid excessive overhead.Monitor connection pool metrics continuously:
- Active connections vs. pool size (saturation indicator)
- Wait time for connection acquisition (queuing indicator)
- Connection creation rate (churn indicator)
- Idle connection count (waste indicator)
- Connection leak warnings (application bug indicator)
Handle connection storms (sudden spike in connection requests) by configuring a connection request queue with a bounded wait time, implementing retry with exponential backoff in the application, and pre-warming the pool during application startup.
Document the connection architecture: application pool size per instance, number of application instances, PgBouncer/ProxySQL settings, database
max_connections, and the maximum theoretical connections formula (instances * pool_size_per_instance).
Output
- PgBouncer/ProxySQL configuration files with optimized pool settings
- Application pool configuration with connection string and pool parameters
- Connection sizing worksheet documenting the calculation from cores to pool size
- Monitoring queries for connection metrics and health checks
- Connection architecture diagram showing application -> pooler -> database flow
Error Handling
| Error | Cause | Solution |
|---|---|---|
FATAL: too many connections for role |
Application pool size exceeds max_connections or connection leak |
Reduce pool size; fix connection leaks (enable leak detection); add PgBouncer for connection multiplexing |
| Connection timeout after 5 seconds | Pool exhausted, all connections in use | Increase pool size cautiously; check for long-running transactions holding connections; add connection queue with backpressure |
connection reset by peer errors |
Server-side idle timeout killed the connection | S |
Установить optimizing-database-connection-pooling в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditGrepGlobBash(psql:*)Bash(mysql:*)Bash(mongosh:*)Вложенные файлы
FAQ
Что делает скилл optimizing-database-connection-pooling?
Process use when you need to work with connection management. This skill provides connection pooling and management with comprehensive guidance and automation. Trigger with phrases like "manage connections", "configure pooling", or "optimize connection usage".
Как установить скилл optimizing-database-connection-pooling?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл optimizing-database-connection-pooling запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic