Connection Pooling Parameters in Connection Strings

Configure connection pool size, timeouts, and idle settings in your database connection strings. Covers pooling for PostgreSQL, MySQL, MongoDB, and ORMs.

Best Practices

Detailed Explanation

What Is Connection Pooling?

Connection pooling reuses a set of pre-established database connections instead of opening a new connection for every query. This dramatically reduces connection overhead and is essential for production applications that handle concurrent requests.

Why Pooling Matters

Opening a database connection involves TCP handshake, authentication, and TLS negotiation — typically 20-100ms per connection. With pooling:

  • A web server handling 100 concurrent requests shares a pool of, say, 20 connections
  • Each request borrows a connection, runs its query, and returns it to the pool
  • No per-request connection setup overhead

Pool Parameters by Database

PostgreSQL (pgBouncer / driver-level)

postgresql://user:pass@host:5432/db?connection_limit=20&pool_timeout=30

When using an external pooler like PgBouncer:

postgresql://user:pass@pgbouncer-host:6432/db?pgbouncer=true

Prisma-specific pooling with pgbouncer=true disables prepared statements, which are incompatible with PgBouncer's transaction pooling mode.

MySQL

mysql://user:pass@host:3306/db?connectionLimit=10&waitForConnections=true&queueLimit=0
Parameter Purpose Default
connectionLimit Max pool size 10
waitForConnections Queue when pool full true
queueLimit Max queue size (0 = unlimited) 0
idleTimeout Close idle connections after (ms) 60000

MongoDB

mongodb://user:pass@host:27017/db?maxPoolSize=50&minPoolSize=5&maxIdleTimeMS=30000
Parameter Purpose Default
maxPoolSize Max connections per host 100
minPoolSize Min idle connections 0
maxIdleTimeMS Idle connection timeout 0 (no limit)
waitQueueTimeoutMS Max wait for connection 0 (no limit)

Sizing Guidelines

A common formula for pool size:

pool_size = (core_count * 2) + effective_spindle_count

For a typical 4-core server with SSD storage, this suggests a pool size of about 10. PostgreSQL's documentation recommends keeping the total connection count (across all application instances) below max_connections, which defaults to 100.

Too many connections waste memory (each PostgreSQL connection uses about 10MB of RAM), while too few cause request queuing. Start conservative and scale based on monitoring.

Use Case

Tuning a production web application to handle high concurrency by configuring the right pool size, preventing connection exhaustion during traffic spikes, and optimizing for serverless environments where connection reuse is critical.

Try It — Connection String Builder

Open full tool