PostgreSQL · sdk · fg-0277

postgres.js through PgBouncer or the Supabase pooler fails with 'prepared statement already exists'

If you see PostgresError: prepared statement "p1" already exists, the cause and the fix for PostgreSQL are below, last verified 2026-10-15.

Verified Oct 2026trust 50/100
Symptom
PostgresError: prepared statement "p1" already existsWorks on the direct port and fails on the transaction pooler port 6543
Cause
postgres.js prepares static queries by default and expects them to stay on the same server session, but a transaction-mode pooler hands each transaction to any session. Supabase states its transaction mode does not support prepared statements.
Fix
Set prepare: false when connecting through a transaction-mode pooler, or use PgBouncer 1.21 or later with max_prepared_statements configured.
Apply
import postgres from 'postgres' const sql = postgres(process.env.DATABASE_URL, { prepare: false })
Affected
postgres.js 3.x (prepare defaults to true) with Supavisor transaction mode or PgBouncer transaction mode before 1.21, as of October 2026; vendor policy, re-check by 2026-12-15
Sources

Last verified 2026-10-15 · Confirmed by 0 builders

Related traps

Have your agent know this before it fails

$ /plugin marketplace add getfootgun/footgun
$ /plugin install footgun@footgun