PostgreSQL: prepared statement does not exist
ERROR: prepared statement "<name>" does not existThe server does not have the prepared statement your client tried to execute. By far the most common cause is a transaction-mode connection pooler such as PgBouncer reusing a backend that never prepared it. Disable server-side prepared statements, or use session mode.
What this error means
Prepared statements live on a specific backend connection. If your driver prepares a statement on one connection but a pooler routes the execute to a different backend, that backend has no such statement, and you get this error.
It also appears after a DEALLOCATE, a session reset, or a server restart between prepare and execute.
How to fix it
A transaction-mode pooler reuses backends
Turn off server-side prepared statements in your driver so each statement is self-contained.
You are using PgBouncer in transaction mode
Either use session mode, or upgrade to PgBouncer 1.21+ which supports prepared statements in transaction mode.
The statement was deallocated or the session reset
Re-prepare on this error, or avoid caching prepared statements across a pooler.
How to avoid it next time
- Match your driver's prepared-statement settings to your pooler mode.
- Disable client prepared-statement caching when running behind a transaction-mode pooler.
Frequently asked questions
Why does this happen with PgBouncer?
In transaction mode PgBouncer hands your queries to different backends. A statement prepared on one backend does not exist on another. Disable server-side prepares or use session mode.
How do I disable prepared statements in my driver?
It varies: JDBC uses prepareThreshold=0, node-postgres avoids named statements, and psycopg can use the simple query protocol or disable the prepared-statement cache.
Stop struggling with SQL
Use FluentDB, the AI database client for macOS.
Related errors
Part of the PostgreSQL error reference. Last reviewed 2026-07-31.