Repository navigation
Open
Labels
area: connectionsConnecting, reconnecting, pooling and poolersdocumentationImprovements or additions to documentationenhancementNew feature or requestupstreamAnswers porsager/postgres reports
Description
Document how to run the client reliably on serverless and behind poolers. Most of the protection comes from configuration the client cannot set by itself.
Content
- Server-side timeouts:
idle_session_timeout,idle_in_transaction_session_timeoutandtcp_keepalives_*, and which failure each one covers. - Transaction-mode poolers (Supavisor, PgBouncer): use
prepare: false. Queries pipelined onto a busy connection can hang or swap results there today (Deadlocked/hung pool when connected to Postgres through Supavisor porsager/postgres#970, Queries get stuck when running static queries in concurrent cron jobs porsager/postgres#1033); documentmax_pipeline: 0as the workaround until it is fixed. Supabase's own postgres.js page saysmax_pipeline: 0breakssql.begin()(sql.begin() always throws UNSAFE_TRANSACTION when max_pipeline is 0 porsager/postgres#1210); say that this applies to upstream and not to this fork. - Hyperdrive: point it at the database itself (for Supabase, the direct connection), never at another pooler's transaction mode, and keep
prepare: true. See the comment of 2026-10-19 for the CI evidence and the vendor docs. - One pool per instance, created outside the request handler, and a smaller
max. - A shorter
connect_timeout. In 4.1.0 it also bounds a graceful close. - Set
idle_timeout. Hand-out expiry in 4.1.0 only closes an idle connection after a freeze ifidle_timeoutis set; it defaults to off, andmax_lifetimealone (30–60 minutes) leaves a long window. - Platform hooks for closing idle connections before suspension, once they are confirmed (see Research serverless platform behaviour for connection handling #8).
Metadata
Metadata
Assignees
Labels
area: connectionsConnecting, reconnecting, pooling and poolersdocumentationImprovements or additions to documentationenhancementNew feature or requestupstreamAnswers porsager/postgres reports
Type
Projects
- StatusShow more project fieldsNext
Activity
okomarov commentedon Oct 17, 2026
For the pooler section: the measured cost of the extra round trip with
prepare: falseis now in the README under Parameter types (once docs/client-measured lands), with the full numbers on #41.parameter_types: 'client'belongs in the recommended pooler setup next toprepare: false; the median query went from 5.3 to 3.1 ms behind the Supabase pooler.The numbers this issue still waits on are the serverless ones from #8 (freeze behaviour, which server timeouts cover which failure).
okomarov commentedon Oct 19, 2026
Findings from the Cloudflare edge tier (#157, #158) and a free Supabase project set up for CI. The vendors' own docs confirm each one.
Hyperdrive in front of a transaction-mode pooler does not work. CI ran the Hyperdrive scenario (50 concurrent insert-and-select pairs,
max: 5,prepare: true) on both builds at two compatibility dates:prepared statement does not exist(26000),CONNECTION_CLOSED, timeouts (run 39234865111)The docs say the same:
prepare: false, which "can cause queries to hang or fail intermittently".So behind Hyperdrive, keep
prepare: trueand point it at the database. Supabase's direct host is IPv6-only on the Free plan, and Hyperdrive reaches it. Its certificate chains to Supabase's private root CA. Workers cannot verify that root over their own sockets, but Hyperdrive can with the CA uploaded andverify-full.Supavisor transaction mode without Hyperdrive. Locally, through port 6543:
prepare: true, one query works, 20 queued on one connection stall after 6, and five connections givedoes not exist.prepare: false, 600 mixed queries andsql.begin()transactions all returned the right rows, with pipelining on and withmax_pipeline: 0.Supabase's postgres.js page now warns that postgres.js pipelining "can hang queries or return mismatched rows" in transaction mode. It also says
max_pipeline: 0"breakssql.begin()transactions instead, a known upstream bug" (porsager#1210). That warning was added in supabase/supabase#50712, which says Supavisor 2.10 will add native pipelining support.That bug does not apply to this fork: it was fixed in 4.0.0 and is covered by the
begin-pipeline-zerolease test (CHANGELOG, 4.0.0), andsql.begin()withmax_pipeline: 0also worked through Supavisor's session and transaction modes. 600 queries do not rule out the hang Supabase describes, somax_pipeline: 0stays the recommendation for transaction mode until Supavisor 2.10, and the docs can say Supabase's caveat is upstream-only.One setup mistake. A role connection limit of 20 produced
CONNECTION_CLOSEDthat looked like pooler failures. Supavisor's logs showed53300 too many connections for role, since Hyperdrive's and Supavisor's pools both count against the role. Size a role's limit for every pool in front of it.okomarov commentedon Oct 20, 2026
The Hyperdrive bullet is covered: docs/api.md, Hyperdrive says to point Hyperdrive at the database itself (Supabase's direct connection, not Supavisor's transaction mode), keep
prepare: true, and usemax: 5andfetch_types: false; the Workers TLS section says certificates are always verified there and a private CA needs Hyperdrive withverify-full. CI runs Hyperdrive in front of Neon (direct and pooled) and Supabase's direct connection on Cloudflare's network on every change. Shipped in 4.6.0-rc1. The other bullets are still open.