PostgreSQL · sdk · fg-0277

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

PostgresError: prepared statement "p1" already exists

Verified 2026-10-15 · Confirmed by 0 builders · Trust 50/100

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 })

Affects: 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

Have your agent know this before it fails

claude mcp add --transport http footgun https://getfootgun.com/api/mcp