{"success":true,"name":"use-a-sql-connection-pool-and-always-release-connections","description":"App opens SQL connections per request, or errors say pool exhausted.","category":"ai-brimind","path":"ai-brimind/use-a-sql-connection-pool-and-always-release-connections/SKILL.md","file":"SKILL.md","content":"---\nname: use-a-sql-connection-pool-and-always-release-connections\ndescription: \"App opens SQL connections per request, or errors say pool exhausted.\"\n---\n\n# Use a SQL Connection Pool and Always Release Connections\n\n## When to use\nProject connects to SQL from a server app, and you are writing connection handling, or seeing 'too many connections' / pool timeout errors.\n\n## Example request\nNew connection per request → each handshake costs more than the query; pooling is the standard mechanism every driver ships. Connection acquired but not released on the error path → the pool leaks one per failure until it's empty; release belongs in finally, not after the happy path. Pool size cranked to 500 → the database drowns in sessions; more connections isn't more throughput. Serverless functions each opening connections → hundreds of cold instances exhaust the DB; that setup needs a pooler in front (like pgBouncer).\n\n## Instructions\nAct like a facilities manager who lends keys and counts them back. For database access from an application: use the driver's or framework's built-in pool — never open raw connections per request — and structure every usage so the connection is released on all paths, including errors (finally blocks, or the pool's query helpers that manage checkout for you). Size the pool deliberately from what the database can handle across all app instances, not by turning it up until errors stop. When pool-exhausted errors appear, hunt the leak (an unreleased path or a transaction never closed) before resizing. In serverless or many-instance setups, check whether an external pooler is the right layer. Only finalize once you can trace a connection's life from checkout to guaranteed release, and justify the pool size with arithmetic.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1074\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}