Plasmic codegen builds are failing on Vercel due to database connection pool exhaustion when pre-rendering pages with data sources.
Environment
Plasmic Setup: Codegen mode
Deployment Platform: Vercel
Issue Description
During the Vercel build process, when Plasmic attempts to pre-render pages that fetch data from our database, the build fails with 31 connection pool errors. It appears that multiple parallel pre-rendering processes are exhausting the available database connections.
Error Messages
1. "remaining connection slots are reserved for non-replication superuser connections"
2. "sorry, too many clients already"
3. TypeError: Cannot read properties of undefined (reading '0')
- This appears to be a secondary error caused by failed data fetching
Full Error Stack
Error: {"error":{"statusCode":400,"__plasmicIgnoreError":true,"message":"remaining connection slots are reserved for non-replication superuser connections"}}
at /vercel/path0/node_modules/@plasmicapp/data-sources/dist/index.js:334:13
at Generator.next (<anonymous>)
at fulfilled (/vercel/path0/node_modules/@plasmicapp/data-sources/dist/index.js:50:24)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
Expected Behavior
Plasmic should manage database connections efficiently during pre-rendering
Connection pooling should be properly configured to handle parallel page generation
Connections should be reused or properly closed after use
Actual Behavior
Database connection limit is reached during build
Multiple “PLASMIC: Encountered error when pre-rendering” messages
Hi @higinio_maycotte, the database in question is on your side right? We can’t adjust how this works from our end since Next.js is making a separate request for each page that’s being built. However, I can think of a few ways you can handle this:
Increase your database’s connection limit.
Add an API server in front of your database to manage connections.
Not sure if it’s possible, but maybe Next.js has a way to limit parallelism of builds, such that only a few pages get built at once?
I had assumed these connection errors were coming from Plasmic’s data fetching service, not our Supabase DB directly. We’re using a large Supabase database mapped through Plasmic Studio, and I understood all data flows through the Plasmic proxy during builds.
If the errors are actually from our Supabase hitting connection limits, is there a way to configure connection pooling on the Plasmic side? Or would it be better to switch to fetching from our API instead of using the database + Plasmic proxy approach?
I was already planning to build custom data components for API fetching - this might accelerate that timeline.
Closing the loop here - this was indeed a Supabase configuration issue, not Plasmic.
The fix: Switched from Supabase’s direct database connection to their Transaction Pooler (Shared “Session Pooler” + using port 6543). This lets thousands of queries share a small pool of actual connections.
For anyone else hitting this with Supabase + Plasmic, just update your integration settings to use the pooled connection string instead of the direct one.
Builds are working perfectly now. Thanks @jason for pointing me in the right direction.