connection-pool-tuner
Diagnoses connection pool exhaustion from captured evidence and sets correct pool sizes and timeouts across app pools and PgBouncer. Use when someone says "we keep hitting database connection limit errors under load", "my API times out waiting for a connection from the pool", "the database shows hundreds of idle connections", or sees "too many clients", checkout/acquire timeouts, "idle in transaction" pile-up, or serverless functions storming the database on a traffic spike. Do NOT use when the problem is an unreliable external service (third-party API, downstream microservice) needing retries or fallbacks - use circuit-breaker-builder instead.
- License 许可
- MIT
- 最近更新
- 2026-10-14
- Stars
- ★ 25
- Forks
- 3
01 前言 Front Matter
- name
- connection-pool-tuner
- metadata
- { "title": "Connection Pool Tuner" }
- description
- Diagnoses connection pool exhaustion from captured evidence and sets correct pool sizes and timeouts across app pools and PgBouncer. Use when someone says "we keep hitting database connection limit errors under load", "my API times out waiting for a connection from the pool", "the database shows hundreds of idle connections", or sees "too many clients", checkout/acquire timeouts, "idle in transaction" pile-up, or serverless functions storming the database on a traffic spike. Do NOT use when the problem is an unreliable external service (third-party API, downstream microservice) needing retries or fallbacks - use circuit-breaker-builder instead.
03 SKILL.md 正文
Connection Pool Tuner
Pool exhaustion shows up as checkout timeouts and "too many clients" errors; the fix is almost never "raise max_connections." Diagnose from evidence first, then size to the database.
Workflow
-
Capture the evidence before touching any number. Query
pg_stat_activitygrouped bystateunder load. Record total connections, count per state, and the longest-running query/transaction age. Also record every pool that points at the DB: app replicas times per-replica pool size, plus migrations and any superuser sessions. -
Classify the failure from the evidence:
- Many
idle in transactionrows -> code opens a transaction and does slow work (an HTTP call, sleep, batch) before commit. Fix the transaction scope, not the pool. - Many
activelong-runners -> slow queries saturating connections. Tune the queries. - Checkout/acquire timeouts while DB connections sit mostly idle -> the app pool is too small or connections leak (not returned to the pool). Find the leak before enlarging.
- Total connections at or above
max_connections-> the sum of pools is too large; reduce per-replica pool or front with a proxy. Do not raisemax_connections.
- Many
-
Size the pool to the database, not the app. Postgres performs best at a small connection count; each backend is a process with real memory cost. Target tens of active connections, not thousands; a common ceiling is roughly
(core_count * 2) + effective_spindle_count. The sum of all pools must stay undermax_connectionswith headroom for migrations and superuser - keep at least 10-15% ofmax_connectionsfree. Twenty replicas with a pool of 20 each is 400 connections - usually far too many. -
Set timeouts that fail fast. Set a pool checkout/acquire timeout (2-5s) so a request errors instead of piling up. Set
idle_in_transaction_session_timeout(30-60s is a sane starting range for web workloads) to kill stuck transactions. Setstatement_timeoutto cap runaway queries - anchor it to your slowest legitimate query plus headroom, often 30s for OLTP paths. In HikariCP, setconnectionTimeoutand keepmaxLifetimea minute or two below the DB/proxy idle cutoff so you never hand out a dead socket. -
Multiplex with PgBouncer when connection count is the bottleneck. Run PgBouncer in transaction pooling mode to fold many client connections onto few server connections. Transaction mode forbids session-level features - prepared-statement caches,
SET, advisory locks held across statements - so configure clients accordingly. -
Tame serverless storms. Serverless/Lambda functions each open their own connection and storm the DB on a spike. Route them through PgBouncer or a serverless pooler/driver (Neon or Supabase pooler, RDS Proxy, Prisma Accelerate) and keep per-function pool size at 1.
-
Verify under load. Re-run the
pg_stat_activityquery and confirm the failing state is gone and total connections sit safely undermax_connections.
Deliverable
Produce a tuning record alongside the config change: the before/after pg_stat_activity readings, the failure classification from step 2 with the evidence that supports it, the full connection budget (every pool times its replicas, plus migration/superuser headroom, summed against max_connections), and each changed setting - pool size, checkout timeout, idle_in_transaction_session_timeout, statement_timeout, maxLifetime, PgBouncer mode - with its one-line justification. The record proves the change fixed the diagnosed cause rather than masking it.
Quality bar
- Every size or timeout change is justified by a captured
pg_stat_activityreading, not a guess. - The sum of all pools, plus migration and superuser headroom, stays under
max_connections. - Each failure mode is traced to its real cause (transaction scope, slow query, or leak) before any pool is enlarged.
Do NOT
- Do NOT raise
max_connectionsor enlarge the pool as the first move - that masks a leak or a slow transaction and adds per-backend memory pressure. - Do NOT prescribe numbers without a captured
pg_stat_activityreading. - Do NOT budget pools per replica in isolation - the database sees the sum across every replica, sidecar, and cron job, and that sum is what exhausts
max_connections. - Do NOT use transaction-mode PgBouncer with clients that rely on session prepared statements,
SET, or cross-statement advisory locks unless reconfigured. - Do NOT leave per-function serverless pools larger than 1.
- Do NOT use this skill for external-service flakiness (retries, fallbacks, backoff) - that is circuit-breaker-builder's job.
Defaults to reach for
Start small: an app pool of 5-10 per replica, a checkout timeout of 2-5s, and a proxy in transaction mode if connection count is the bottleneck. If raising the pool fixes latency, you had a leak or a slow transaction - find it rather than masking it.
04 同仓库更多 Skills
zone-2-cardio-plan
Use when someone asks to build a steady-state cardio plan, train an aerobic base or Zone 2, structure easy or endurance weekly cardio, train by heart-rate zones, or improve resting heart rate, VO2, or endurance. Builds a heart-rate-zone aerobic training block with session structure, modality choice, and progression. General fitness guidance, not medical advice. Do NOT use to design a strength or lifting program (use Strength Training Plan), high-intensity interval conditioning, HIIT, or circuits (use Conditioning & HIIT Program), or a mobility/flexibility routine (use Mobility Routine).
youtube-script-writer
Writes retention-engineered long-form YouTube scripts on a hook/body/payoff architecture - a first-30-seconds hook that survives the retention cliff, a beat-sheet body with mini-hooks and bridges, timed pattern interrupts, and a payoff that over-delivers - with B-roll and editing cues marked inline. Use when someone says "script my next video", "my retention graph dies at the start", "tighten this draft", or "outline a video on X". Do NOT use for the 3-second opener of TikTok, Reels, or Shorts - use video-hook-writer instead; do NOT use for spoken voiceover synced to on-screen tutorial actions - use narration-script instead; do NOT use for a sales demo built on a buyer's discovery notes - use demo-script instead; do NOT use to design the thumbnail and title - use thumbnail-concept instead.
win-back-campaign
Designs segmented win-back email sequences for dormant users - dormancy tiers, a three-beat sequence with a single proportional incentive, and a suppression rule - and measures success by re-activation, not opens. Use when someone says "our users went quiet", "design a win-back campaign", "how do I re-engage lapsed customers", "should we email people who haven't logged in for months", or lifecycle messaging has stopped landing with a lapsed segment. Do NOT use for recovering an unfinished checkout - use abandoned-cart-sequence instead. Do NOT use for diagnosing and fixing why active customers cancel - use churn-reduction instead. Do NOT use for building always-on onboarding or nurture flows - use email-drip-builder instead.
wikipedia-style
Writes neutral, verifiable, encyclopedic prose following Wikipedia's core content policies and manual of style - NPOV, inline citations, notability-backed claims, and a strict ban on promotional language. Use when someone asks "write this like a Wikipedia article", "draft a Wikipedia page for this company or person", "make this neutral and encyclopedic", or "why does my article draft keep getting rejected". Do NOT use for persuasive or opinion writing - use op-ed-writer instead; for thesis-driven academic papers, use academic-essay; for verifying claims in existing text, use fact-checker.
whitepapers
Structures and writes authoritative B2B whitepapers - a standalone executive summary, a data-sized problem statement, methodology, evidence-driven findings, recommendations, and a soft call to action - flagging every claim that needs a real citation. Use when a marketer asks "write a whitepaper on this topic", "turn our research into a lead-gen asset", "make this credible enough for executives", or a draft reads like a product pitch instead of analysis. Do NOT use for customer-story-driven proof - use case-study-builder instead; for policy audiences, use policy-brief.
white-space-analysis
Finds unmet market gaps by ranking jobs-to-be-done on importance versus satisfaction, overlaying them against current solutions and workarounds, and validating that each gap is real, winnable, and worth winning. Use when someone asks "where are the gaps in this market", "what's underserved here", "where should we play next", or is hunting for product, feature, or market-entry opportunities. Do NOT use for profiling competitors and building battle cards - use competitive-intelligence instead; for putting a dollar figure on an identified opportunity - use market-sizing instead; for extracting jobs-to-be-done from raw customer interviews - use jtbd-extractor instead.