How to Fix Supabase Connection Pool Exhausted in AI-Built Apps
Your app runs out of database connections, causing queries to hang or fail. AI-generated code often creates new Supabase clients per request instead of reusing a shared instance.
Error messages you might see
Error: remaining connection slots are reserved for non-replication superuser connectionsError: too many clients already, max pool size reachedWhy this happens in AI-generated code
Creating clients per request
AI code calls `createClient()` inside request handlers, opening a new connection for every API call.
Not using connection pooler
AI connects directly to Postgres instead of through Supabase's PgBouncer connection pooler.
Unclosed connections in serverless
Serverless functions open connections that aren't reused, exhausting the pool across cold starts.
How to fix it
Use a singleton Supabase client
Create the Supabase client once in a shared module and import it everywhere. Never call `createClient()` inside handlers.
Use the connection pooler URL
Connect via the pooler URL (port 6543) instead of the direct connection (port 5432) for serverless deployments.
Get professional help
Our code audit identifies this issue and provides a fix. Start at springcode.co/products for $19.
Can't fix it yourself?
Our code audit identifies this issue and dozens more. Get a prioritized fix list.
Security Review
Automated Security Scan
AI-powered analysis of your codebase. Get a detailed report with prioritized findings within 24 hours.
Get StartedSecurity Review
Manual Security Review
Expert engineer works on your project directly. Fixed scope, fixed price, no surprises.
Get a QuoteSecurity Review
Full Pentest
Enterprise-grade engagement tailored to your needs. Dedicated engineer, ongoing support.
Fix Bugs
Code Audit
AI-powered analysis of your codebase. Get a detailed report with prioritized findings within 24 hours.
Get StartedFix Bugs
Bug Fixing
Expert engineer works on your project directly. Fixed scope, fixed price, no surprises.
Get a QuoteFix Bugs
Ongoing Support
Enterprise-grade engagement tailored to your needs. Dedicated engineer, ongoing support.
Refactor Code
Code Audit
AI-powered analysis of your codebase. Get a detailed report with prioritized findings within 24 hours.
Get StartedRefactor Code
Refactoring
Expert engineer works on your project directly. Fixed scope, fixed price, no surprises.
Get a QuoteRefactor Code
Full Rewrite
Enterprise-grade engagement tailored to your needs. Dedicated engineer, ongoing support.
100% of your audit purchase is credited toward any paid service. Start with an audit, then let us fix what we find.
Frequently asked questions
How many connections does Supabase allow?
Free tier allows around 60 direct connections. Use the connection pooler in transaction mode for serverless, which supports thousands of concurrent clients.
What is the difference between session and transaction pooling?
Transaction mode releases connections after each query, ideal for serverless. Session mode holds connections for the client lifetime, better for long-lived servers.
Related resources
Related Technologies
Still stuck? We can fix it for you.
Send us your repo. We'll diagnose the issue and give you a fixed quote within 24 hours.