How it works
The pooler runs in transaction mode: an app connection gets a server connection for one transaction, then gives it back. Between transactions, the next statement may run on a different server connection.
The plan sets both limits, for example 25 direct and 200 pooled connections on the 1 GB plan. See Plans and sizing.
When to use it
Use the pooler by default. Use direct for:- Schema migrations (Prisma Migrate, Rails, Django, Flyway): many tools need one session for the whole migration.
LISTEN/NOTIFY, advisory locks held across transactions,SETthat should last for the session, temporary tables.pg_dump,psqlsessions and other admin work.
Trade-offs
- Session state does not survive between transactions on the pooler:
SET, temporary tables and session-level prepared statements belong on the direct address. - Some drivers use prepared statements by default. With Prisma, add
pgbouncer=trueto the pooled URL; most other drivers work as they are. - A common setup:
DATABASE_URLon the pooler for the app,DIRECT_URLon port 5432 for migrations.
Related
Connect to a database
Both addresses, ready to copy.
Plans and sizing
Connection limits per plan.