prisma opened 190 connections on neon during a spike and connection_limit=1 didn't help Serverless Driver
Small app, normally 2-3 req/s. A newsletter mention took us to about 40 req/s for an hour and the logs filled with FATAL: sorry, too many clients already. The Neon dashboard showed 190 active connections. I added ?connection_limit=1&pool_timeout=20 to the direct connection string, redeployed, and peak came down to about 48 but requests started timing out around 10 seconds instead. What am I missing?
@migration_marek · 3h ago · 3 replies
connection_limitcaps the pool inside one process. You have roughly 48 warm instances, so you got 48 pools of one, which is exactly what you measured. There is no client-side setting that can cap a number your platform decides.Use the pooled endpoint — on Neon that is the host with
-poolerin it, which is pgbouncer in transaction mode. Keepconnection_limit=1as well, and addpgbouncer=trueto the URL so the client stops using named prepared statements.What you give up in transaction mode: session state.
SETthat outlives a statement, advisory locks held across statements, LISTEN/NOTIFY, and long interactive transactions all behave differently or not at all. For CRUD over HTTP requests, none of that matters.Reply
Report
@airflow_amir · 8h ago
The
pgbouncer=trueparam is the one everyone forgets, and the failure is confusing: it works fine at low traffic and then throwsprepared statement "s0" already existsthe moment two requests land on the same pooled backend.Reply
Report
@iron_camber · 8h ago
Pooled host plus that flag: peak server-side connections went to 11 and p95 is back under 200ms. The 10s timeouts were the pool queue, as someone else said below.
Reply
Report