skip to content

In Prisma 7 with PrismaPg, where do you set the connection pool size and timeouts, and which defaults changed from Prisma 6?

level: middleimportance: should knowfreq 25%

answer

  1. the driver owns the pool now
  2. constructor options, not URL parameters
  3. node-postgres defaults
  4. an acquire wait with no limit

basics

~20 s

In Prisma 7 the pool belongs to node-postgres, so you set it in the PrismaPg constructor: max (default 10), connectionTimeoutMillis (default 0, no limit) and idleTimeoutMillis (default 10 seconds). Prisma 6's connection_limit and pool_timeout URL parameters no longer apply.

solid answer

~40 s

Since Prisma 7 the pool comes from the database driver, not from Prisma. `new PrismaPg(...)` from `@prisma/adapter-pg` takes a node-postgres pool config, a connection string or an existing `pg.Pool`, and builds a `pg.Pool` when the client connects. The defaults are therefore the driver's: `max` 10, `connectionTimeoutMillis` 0 (wait for a free connection without limit), `idleTimeoutMillis` 10 seconds and `maxLifetimeSeconds` 0. Prisma 6 sized its own pool at physical CPUs times two plus one, gave up waiting after a 10-second `pool_timeout`, and read those settings from URL parameters such as `connection_limit`; Prisma 7 has no URL parameters for the pool. So after an upgrade, a saturated pool makes requests wait instead of failing unless you set `connectionTimeoutMillis`.

code

typescript · 11 lines
typescript
import { PrismaPg } from "@prisma/adapter-pg";
import { PrismaClient } from "../generated/prisma/client";

const adapter = new PrismaPg({
  connectionString: process.env.DATABASE_URL,
  max: 5,
  connectionTimeoutMillis: 5_000,
  idleTimeoutMillis: 300_000,
});

export const prisma = new PrismaClient({ adapter });

go deeper

for a junior

Recall that in Prisma 7 the pool is configured on the adapter, with options such as max, not in the connection URL.

for a middle

Walk through the pg defaults (max 10, no acquire timeout, 10-second idle) and how each differs from the Prisma 6 values.

for a senior

Diagnose post-upgrade hangs and reconnect churn from these defaults, and set bounded waits deliberately rather than copying old URL parameters.

for a principal

Make pool settings an explicit, reviewed part of the deployment, multiplied by instance count, rather than an inherited driver default.

## Who owns the pool in Prisma 7 A **connection pool** keeps open database connections and lends one to each query, so the application does not pay for a new connection every time. In Prisma 6 the pool lived inside Prisma's query engine and was tuned through parameters appended to the connection URL. In Prisma 7 every relational database is reached through a **driver adapter**, and the adapter delegates pooling to the underlying Node.js driver. For PostgreSQL the adapter is `PrismaPg` from `@prisma/adapter-pg`, and the driver is node-postgres (`pg`). So the question "how big is Prisma's pool?" has a new answer: it is a `pg.Pool`, configured with node-postgres options and created when the client first connects. ## Three ways to construct PrismaPg - **A config object**: `new PrismaPg({ connectionString, max, connectionTimeoutMillis, ... })`. The object is a node-postgres pool config, so any pool option is accepted. - **A connection string**: `new PrismaPg(process.env.DATABASE_URL)`. You get node-postgres defaults for everything else. - **An existing pool**: `new PrismaPg(pool)` with a `pg.Pool` you created. The adapter uses it as is. On `$disconnect()` it leaves that pool open unless you pass `disposeExternalPool: true` in the adapter's second argument, which also accepts `onPoolError` and `onConnectionError` callbacks. ## The settings and their defaults | Behaviour | Prisma 6 URL parameter | Prisma 6 default | `pg` option in Prisma 7 | Prisma 7 default | |---|---|---|---|---| | Pool size | `connection_limit` | physical CPUs x 2 + 1 | `max` | `10` | | Wait for a free connection | `pool_timeout` | 10 s | `connectionTimeoutMillis` | `0` (no limit) | | Time to open a connection | `connect_timeout` | 5 s | `connectionTimeoutMillis` | `0` (no limit) | | Idle connection closed after | `max_idle_connection_lifetime` | 300 s | `idleTimeoutMillis` | `10 s` | | Maximum connection age | `max_connection_lifetime` | none | `maxLifetimeSeconds` | `0` (none) | The Prisma 7 docs state it plainly: there are no connection URL parameters for pool size or timeouts any more. A `connection_limit=5` left in the URL is not a Prisma 7 pool setting; `max` is. ## What the new defaults mean in production 1. **No acquire timeout.** With `connectionTimeoutMillis` at `0`, a query that finds all `max` connections busy waits until one is released. Under sustained overload, requests pile up and time out at the HTTP layer instead of failing fast inside the data layer. Set `connectionTimeoutMillis` if you want a bounded wait. 2. **Short idle lifetime.** Idle connections close after 10 seconds, where Prisma 6 kept them for 300. Spiky traffic reconnects more often; raise `idleTimeoutMillis` if reconnect cost shows up in latency. 3. **A fixed size.** `max` is 10 regardless of the machine. The total the database sees is `max` times the number of processes or instances running the client. ## Errors you will meet - When PostgreSQL itself refuses a connection because its own limit is reached (SQLSTATE `53300`), the adapter maps it to Prisma error **`P2037`**, "Too many database connections opened". - When the server cannot be reached at all, the client reports **`P1001`**. - Waiting for a pool slot under the default settings produces no error: it simply waits. ## Restoring Prisma 6 behaviour If an upgrade surfaces hangs or reconnect churn, the docs suggest passing Prisma 6-like values to the adapter, as the code example on this page does. Choosing the right `max` for your database is a general pool-sizing question; what Prisma 7 changes is only where you write the number. ## An upgrade checklist for pool settings When a Prisma 6 project moves to Prisma 7, walk through the old connection string and translate each piece: - Remove `connection_limit`, `pool_timeout`, `connect_timeout` and the lifetime parameters from the URL, and write the equivalent `pg` options on `PrismaPg` instead. - Decide on purpose whether `connectionTimeoutMillis` should stay at `0`. A bounded value makes overload visible as errors in your logs instead of slow requests. - Re-check `max` against the number of processes or instances you run. Prisma 6's CPU-based default may have been larger or smaller than 10 on your machines, so the total connection count can move in either direction after the upgrade. - Keep TLS options in mind too: Prisma 7 talks to PostgreSQL through node-postgres, so certificate handling follows the driver, and the adapter config is where an `ssl` option goes.

  • What changes if you pass your own pg.Pool to PrismaPg instead of a config?
    `PrismaPg` uses that pool as is, attaches an error listener, and takes its options from it. When the client disconnects, the adapter by default only detaches its listener and leaves the pool open, since other code may share it. Pass `disposeExternalPool: true` in the adapter's options to have `$disconnect()` end the pool as well.
  • Which Prisma error tells you PostgreSQL refused a connection for being over its limit?
    With `PrismaPg`, PostgreSQL's SQLSTATE `53300` is mapped to `P2037`, "Too many database connections opened". That is the server's limit. A client-side wait for a free pool connection is different: with the default `connectionTimeoutMillis` of 0 it produces no error and simply waits.

  • Adding connection_limit=5 to DATABASE_URL caps PrismaPg's pool in Prisma 7.
  • Prisma 7 still sizes the pool from the number of CPU cores.
  • A full PrismaPg pool fails with P2024 after ten seconds by default.
  • PrismaPg keeps idle connections open for five minutes, like Prisma 6.

Assumes Prisma 7 with @prisma/adapter-pg, where pool settings and defaults come from node-postgres; Prisma 6 configured its own pool through URL parameters.