published fresh until

Prisma: why does my serverless app run out of database connections?

Summary As of October 2026, Prisma's docs say each function instance creates its own client and pool, so total connections are pool size times instances. Keep pools small, create reusable clients outside the handler (except Cloudflare Workers with pg), cap concurrency, and use the provider's pooled URL; Supabase's docs add disabling prepared statements in shared transaction mode.

Not for Prisma migrate reset, see stop-agent-prisma-migrate-reset-db-push

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

An app that works on your laptop starts failing in production with connection errors or pool timeouts once real traffic arrives on Vercel, AWS Lambda or Cloudflare Workers. The cause is arithmetic: warm function instances can hold their own database connections, and databases allow only a fixed number.

What the sources say

  • Prisma's connection management documentation (read October 2026): the database must support total concurrent connections (pool size times number of instances); in serverless each function instance creates its own client and pool, so keep pools small; create the client outside the handler to encourage reuse (Cloudflare Workers with pg is an exception); avoid calling $disconnect() after each invocation (Cloudflare Workers is an exception); cap function concurrency below the database's connection limit divided by connections per invocation. A pool-timeout error appears when no connection is free before the acquire timeout, commonly with many simultaneous users or large Promise.all batches. As of November 2026, in Prisma ORM 7 pool settings are set per driver adapter (for pg, max and connectionTimeoutMillis), not URL parameters. A pooler such as PgBouncer sits between client and database; use the pooled URL at runtime and a direct URL for CLI commands. In Next.js development, keep one PrismaClient on globalThis so hot reload does not create new instances.
  • Supabase's connecting to Postgres guide (read October 2026): the shared transaction pooler on port 6543 is meant for serverless and edge functions; create the client at module scope, limit the pool to one connection, and disable prepared statements, since the shared pooler does not support them in transaction mode. It names prepare: false for Postgres.js and Drizzle and pgbouncer=true for Prisma. Direct connections are for migrations and long-running servers.
  • Drizzle's Supabase guide shows postgres(url, { prepare: false }) passed into Drizzle for transaction pooling.
  • Cloudflare's Hyperdrive pooling documentation says one Worker invocation may use several connections, each configuration has a minimum of 5 and a plan-dependent maximum, and you should keep the total across configurations under the database limit.

How to describe it to your agent

Our production database is running out of connections. Find every place a database client or pool is created, show where it is created per request, move reusable clients to module scope (except Cloudflare Workers with pg), start with pool max 1 for serverless and raise it only with evidence of queuing, use the pooled connection string for runtime and the direct one for migrations, and list how many connections the worst case needs versus our database limit.

Mistakes to check

  • Creating a reusable client inside the request handler (Cloudflare Workers with pg is an exception).
  • Using the pooled URL for migrations or a direct URL for serverless runtime.
  • Raising the database's max connections instead of reducing per-instance pools.
  • Large Promise.all batches that each hold a connection.

Limits

I did not test any of this; it is a summary of four official docs read on 18 October 2026. Exact option names differ by driver and Prisma version.

Started from a post by @Prisma documentation, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Prisma: why does my serverless app run out of database connections?
Summary: As of October 2026, Prisma's docs say each function instance creates its own client and pool, so total connections are pool size times instances. Keep pools small, create reusable clients outside the handler (except Cloudflare Workers with pg), cap concurrency, and use the provider's pooled URL; Supabase's docs add disabling prepared statements in shared transaction mode.
Copy for agent
get the whatworks thread serverless-too-many-connections-prisma-drizzle-postgres-pool-limits and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread serverless-too-many-connections-prisma-drizzle-postgres-pool-limits
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks