Group
  • Performance

    Diagnose my database connection pool exhaustion

    Find why your app runs out of database connections under load and fix pool sizing, leaks, and idle hogs.

    • Debug & fix
    • Improve quality
    • Advanced
    • General

Free Prompt

Under load (or randomly), my app throws errors about failing to get a database connection, requests pile up and time out, and restarting the app temporarily fixes it. Diagnose and fix my connection exhaustion: 1. Establish the facts: my database's max connection limit, my app's pool size per process, and how many processes/instances run. The math often fails here: 10 app instances each opening a pool of 10 connections against a database that allows 60 total. 2. Check for connection leaks: code paths that check out a connection and never release it (errors thrown mid-query, missing release in a finally path, transactions left open). A leak explains the 'restart fixes it for a while' pattern. 3. Find connection hogs: long-running queries, reports or exports run through the app pool, or per-request code that opens multiple connections instead of reusing one. 4. Check for serverless-specific issues if applicable: each function instance creating its own pool, cold instances multiplying connections, no external pooler (like PgBouncer or the managed equivalent) in front of the database. 5. Fix what's found: right-size the pool relative to the database limit and instance count, fix leak paths with proper finally/release handling, move heavy queries off the request path or onto a separate pool, and add monitoring on pool saturation so I see it coming next time. Don't just crank the pool size up; that moves the failure into the database. The deliverable is the diagnosis (which of these it actually was), the fixes, and how to verify: a load test or reproduction that previously exhausted connections now passing, plus the monitoring I should watch.

What This Does / How This Helps

This works through why your app runs out of database connections: pool math versus your database limit, leaked connections, long-running hogs, and serverless pool multiplication, then fixes the actual cause. Connection exhaustion is a classic launch-week outage: everything is fine at ten users, then traffic arrives, connections run out, and every request (even ones that barely touch the database) queues until the whole app appears down. The restart-fixes-it pattern means the cause was never addressed, so it returns at the worst moment, usually during your best traffic day. Getting the pool math and leak paths right before launch prevents one of the most common self-inflicted outages.

Want to skip doing this by hand?

Fortivibe audits your app for all of the areas these prompts cover (and more).

See What We Check

Related Prompts