# Postgres connection limit in serverless: why it happens and the pooler fix

> A serverless function fleet can open one Postgres connection per invocation and exhaust max_connections in minutes. Why direct connections fail at scale and how a pooled (PgBouncer-style) connection string fixes it.

Source: https://scribase.com/postgres-connection-limit-serverless

A function that works fine at low traffic can start throwing connection errors the moment it scales to dozens of concurrent invocations — not because the query is slow, but because each invocation opened its own direct Postgres connection, and Postgres has a hard cap on how many of those exist at once.

## Why serverless makes this worse than a normal app

A traditional server process opens a small, fixed pool of database connections once at startup and reuses them for every request. A serverless function has no equivalent long-lived process to hold a pool open across invocations by default — each cold invocation can open its own connection, and a traffic spike that scales to hundreds of concurrent invocations means hundreds of simultaneous direct connections, fast.

Postgres caps total connections with max_connections, a fixed number regardless of how many different clients are trying to connect. Once that number is in use, every new connection attempt is refused outright, including the one request that would have succeeded if it had just waited a moment.

## The fix: a pooled connection string, not a bigger database

A pooler sitting in front of Postgres (PgBouncer is the common one; Neon and Supabase both run one) accepts far more client connections than the database's own max_connections — up to 10,000 client connections on Neon's pooler, for example — and multiplexes them down onto a much smaller number of real Postgres backend connections. Point the serverless function at the pooled hostname (often a -pooler suffix) instead of the direct one, and the same invocation fleet that exhausted direct connections in minutes runs inside the pooler's much larger client ceiling.

A pooler is not a substitute for closing connections cleanly: a function that opens a connection and never releases it still eventually exhausts even the pooler's own client-connection ceiling, just at a much higher number than the direct limit.

## Sources

- [Neon: Connection pooling](https://neon.com/docs/connect/connection-pooling)

## Scribase pools application traffic by default

Every Scribase project runs behind a pooler by default for application traffic — a serverless function fleet does not need to find the right -pooler hostname or make a separate upgrade decision mid-incident, because the pooled path is what application traffic uses from the start. Direct Postgres connections from the internet are not open yet on Scribase; migrations, the console SQL editor and the HTTP serverless driver work today and do not compete with the app's own connection budget.

Every project is $5 a month on Hobby or $25 on Pro, with no separate connection-pooling add-on to buy — pooling is part of the base project, not a tier gate.

## Sources

- [Scribase pricing](https://scribase.com/pricing)

## FAQ

**Does using an ORM's own connection pool fix this?**

Partially, within one running instance: an ORM-level pool reuses connections inside a single long-lived process. It does not help a serverless deployment where each cold invocation is its own process with no shared pool across invocations — that still needs a pooler in front of Postgres, not just inside the app.

**What error message shows up when connections are exhausted?**

Typically "FATAL: remaining connection slots are reserved for roles with the SUPERUSER attribute" (the database-level max_connections cap reached) or, when hitting a pooler's own client-connection ceiling instead, "FATAL: sorry, too many clients already".

**Is this specific to AWS Lambda, or does it happen on Vercel/Cloudflare Workers too?**

It happens on any platform where a function invocation can run as its own process without a shared, persistent connection pool across invocations — Lambda, Vercel serverless and edge functions, and Cloudflare Workers all share the same underlying pattern, even though each platform's concurrency model differs.

**Does upgrading to a bigger database compute size fix it permanently?**

It raises the ceiling (a bigger compute size generally raises max_connections too), but does not fix a fleet that is opening more connections than it closes — a pooled connection string fixes the actual cause; a bigger compute size just delays hitting it again.

## Related

- [Supabase too many connections](https://scribase.com/supabase-too-many-connections)
- [Neon too many connections](https://scribase.com/neon-too-many-connections)
- [Prisma P1001: can't reach database](https://scribase.com/prisma-p1001-cant-reach-database)
- [Prisma P2024: connection pool timeout](https://scribase.com/prisma-p2024-connection-pool-timeout)
- [Connection string checker](https://scribase.com/tools/connection-string)
- [Vercel Postgres deprecated](https://scribase.com/vercel-postgres-deprecated)