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 Scan
Black-box review of your public-facing app. No code access needed.
- OWASP Top 10 checks
- SSL/TLS analysis
- Security headers
- Expert review within 24h
Code Audit
In-depth review of your source code for security, quality, and best practices.
- Security vulnerabilities
- Code quality review
- Dependency audit
- AI pattern analysis
Complete Bundle
Both scans in one package with cross-referenced findings.
- Everything in both products
- Cross-referenced findings
- Unified action plan
100% 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.