Setup and ConfigurationDatabase Connections

Connection pool

Prisma Client uses a connection pool (from the database driver or driver adapter) to store and manage database connections.

Quick summary

This page explains how Prisma ORM manages database connections using a connection pool, and how you can configure limits and timeouts for optimal performance.

Prisma Client uses a connection pool of database connections (managed by the database driver when using driver adapters). The pool is created when Prisma Client opens the first connection to the database, which can happen in one of two ways:

Relational database connectors use Prisma ORM's own connection pool, and the MongoDB connectors uses the MongoDB driver connection pool.

Questions answered in this page
  • How do I size Prisma's connection pool?
  • How do I set pool timeouts and limits?
  • When should I use PgBouncer with Prisma?

Relational databases

Starting with Prisma ORM v7, relational datasources instantiate Prisma Client with driver adapters by default. Driver adapters rely on the Node.js driver you supply, so connection pooling defaults (and configuration) now come from the driver itself.

Use the tables below to translate Prisma ORM v6 connection URL parameters to the Prisma ORM v7 driver adapter fields alongside their defaults.

Prisma ORM v7 driver adapter defaults

The following tables document the default connection pool settings for each driver adapter.

Prisma timeouts

Prisma ORM also has its own configurable timeouts that are separate from the database driver timeouts. If you see a timeout error and are unsure whether it comes from the driver or from Prisma Client, see the Prisma Client timeouts and transaction options documentation.

PostgreSQL (using the pg driver adapter)

Here are the default connection pool settings for the pg driver adapter:

Behaviorv6 URL parameterv6 defaultv7 pg config fieldv7 default
Pool sizeconnection_limitnum_cpus::get_physical() * 2 + 1max10
Acquire timeoutpool_timeout10sconnectionTimeoutMillis0 (no timeout)
Connection timeoutconnect_timeout5sconnectionTimeoutMillis0 (no timeout)
Idle timeoutmax_idle_connection_lifetime300sidleTimeoutMillis10s
Connection lifetimemax_connection_lifetime0 (no timeout)maxLifetimeSeconds0 (no timeout)
Example: Matching Prisma ORM v6 defaults with the pg driver adapter

If you want to preserve the same timeout behavior you had in Prisma ORM v6, pass the following configuration when instantiating the driver adapter:

import { PrismaPg } from "@prisma/adapter-pg";

const adapter = new PrismaPg({
  connectionString: process.env.DATABASE_URL,
  // Match Prisma ORM v6 defaults:
  connectionTimeoutMillis: 5_000, // v6 connect_timeout was 5s
  idleTimeoutMillis: 300_000, // v6 max_idle_connection_lifetime was 300s
});

See the node-postgres pool documentation for details on every available option.

MySQL or MariaDB (using the mariadb driver)

Here are the default connection pool settings for the mariadb driver adapter:

Behaviorv6 URL parameterv6 defaultv7 mariadb config fieldv7 default
Pool sizeconnection_limitnum_cpus::get_physical() * 2 + 1connectionLimit10
Acquire timeoutpool_timeout10sacquireTimeout10s
Connection timeoutconnect_timeout5sconnectTimeout1s
Idle timeoutmax_idle_connection_lifetime300sidleTimeout1800s
Example: Matching Prisma ORM v6 defaults with the mariadb driver adapter

If you want to preserve the same timeout behavior you had in Prisma ORM v6, pass the following configuration when instantiating the driver adapter:

import { PrismaMariaDb } from "@prisma/adapter-mariadb";

const adapter = new PrismaMariaDb({
  host: "localhost",
  port: 3306,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  // Match Prisma ORM v6 defaults:
  connectTimeout: 5_000, // v6 connect_timeout was 5s
  idleTimeout: 300, // v6 max_idle_connection_lifetime was 300s (note: in seconds, not ms)
});

Refer to the MariaDB Connector/Node.js pool options for configuration and tuning guidance.

SQL Server (using the mssql driver)

Here are the default connection pool settings for the mssql driver adapter:

Behaviorv6 URL parameterv6 defaultv7 mssql config fieldv7 default
Pool sizeconnection_limitnum_cpus::get_physical() * 2 + 1pool.max10
Connection timeoutconnect_timeout5sconnectionTimeout15s
Idle timeoutmax_idle_connection_lifetime300spool.idleTimeoutMillis30s
Example: Matching Prisma ORM v6 defaults with the mssql driver adapter

If you want to preserve the same timeout behavior you had in Prisma ORM v6, pass the following configuration when instantiating the driver adapter:

import { PrismaMssql } from "@prisma/adapter-mssql";

const adapter = new PrismaMssql({
  server: "localhost",
  port: 1433,
  database: "mydb",
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  // Match Prisma ORM v6 defaults:
  connectionTimeout: 5_000, // v6 connect_timeout was 5s
  pool: {
    idleTimeoutMillis: 300_000, // v6 max_idle_connection_lifetime was 300s
  },
});

See the node-mssql pool docs for details on these fields.

MongoDB

The MongoDB connector does not use the Prisma ORM connection pool. The connection pool is managed internally by the MongoDB driver and configured via connection string parameters.

External connection poolers

The pool size cannot exceed what the underlying database can support. Configure pool size and timeouts via your driver adapter (see the tables above). This is a particular challenge in serverless environments, where each function manages an instance of PrismaClient and its own connection pool.

Consider introducing an external connection pooler like PgBouncer to prevent your application or functions from exhausting the database connection limit.

Manual database connection handling

When using Prisma Client with a driver adapter, database connections are managed by the driver and its pool. They are not exposed to the developer and it is not possible to manually access individual connections.

On this page