Anish Logo
  • enflagEnglish (US)
  • npflagनेपाली(NP)
  • Home
  • Tools
  • Pricing
  • Blogs
Code

Connection pooling limit in nextjs & supabase

Anish Shrestha
February 22, 2025
4 min
Connection pooling limit in nextjs & supabase
I encountered some issues while deploying and using my web app. I built it using Next.js and deployed it on Vercel. Despite using the default settings and Vercel's database without modifying any environment files, I ran into a problem: a "Connection pooling limit reached" error. After extensive research, I couldn’t find a solution, so I created multiple simple projects to troubleshoot the issue. I also tested different databases, such as Neon, but the same error persisted. Here’s an explanation of the problem: When Vercel deploys a Next.js app, it automatically makes it serverless. Each serverless function creates a new database connection when it interacts with the database. This error occurs because there’s a limit on the number of open connections. When the app experiences high traffic or multiple users access it simultaneously, the database reaches its connection pooling limit, triggering the error. To resolve this, I followed the Supabase documentation, which clearly states that to use a database with serverless functions, specific parameters must be included in the connection setup: pool_mode=transaction&supa=base-pooler.x&pgbouncer=true In this configuration, the pool mode is set to "transaction," and Pgbouncer is enabled (pgbouncer=true). Pgbouncer is a tool that maintains a single database connection instead of creating multiple connections within a short time frame, effectively managing the connection pool.
Supabase connection pool error
connection pool limit