Skip to content

Connection pooling

Tested with: PostgreSQL 17 pooler (transaction mode) · pg 8.13 · psycopg_pool 3.2 · pgx v5.7

Every size has a max_connections ceiling (see the size catalogue). The engine enforces it and the gateway rejects the excess early with a protocol-appropriate error rather than letting clients hang.

Use your driver’s pool with a size well under the ceiling, divided by the number of replicas of your service:

RuntimeSetting
Node (pg, mysql2)max / connectionLimit: 10 per process
Python (psycopg_pool, SQLAlchemy)max_size / pool_size: 5 to 10, max_overflow: 0
Go (pgxpool, database/sql)pool_max_conns / SetMaxOpenConns: 10
JVM (HikariCP)maximumPoolSize: 10, connectionTimeout: 10 s
.NET (Npgsql, MySqlConnector)Max Pool Size: 20 (per process)
Rails, Django, LaravelMatch the web-worker count; see the framework guides

Reserve roughly 10 connections for backups, migrations and psql.

Serverless and edge: the built-in pooler (PostgreSQL)

Section titled “Serverless and edge: the built-in pooler (PostgreSQL)”

Functions open a connection per invocation and cannot share a process pool. PostgreSQL instances include a transaction-mode pooler (PgBouncer semantics) that multiplexes thousands of short client connections onto a small server pool.

  • Enable it on Instance → Connect → Pooler. The pooled endpoint has the same host with -pool appended and the same port; the connection string is shown next to the direct one.
  • Use the pooled endpoint from Vercel, Netlify, Cloudflare Workers, Lambda and Cloud Run; use the direct endpoint for migrations, LISTEN/NOTIFY, advisory locks and anything that needs session state.
  • Prepared statements work per transaction; ORMs need the flag for that (?pgbouncer=true for Prisma, prepare: false for postgres.js, statement_cache_size=0 for asyncpg).
  • MySQL: no transaction pooler yet; use the driver pool and keep it small on serverless (2 to 5).
  • Valkey: one multiplexed client per process; no pool needed.
  • FerretDB: the MongoDB driver’s pool (maxPoolSize); each connection is a PostgreSQL connection underneath.
  • libSQL: HTTP; no connection to keep. Use embedded replicas on runtimes with a filesystem.