Incident brief
Prepared statement does not exist
EXECUTE or DEALLOCATE of a prepared-statement name that was never prepared (or was already deallocated) raises this invalid-statement-name error.
What lands in your log
ERROR: prepared statement "monthly_report" does not exist
In 10 seconds
- What triggers it
- EXECUTE a prepared-statement name that has not been PREPAREd in this session.
- Fix
- PREPARE the statement before you EXECUTE it, in the same session.
- Proof
- Reproduced on PostgreSQL 18.4 → An EXECUTE reproduces SQLSTATE 26000 because the named statement was never prepared in this session.
Fix
What to do right now
Application-level steps for this error.
- PREPARE the statement before you EXECUTE it, in the same session.
- Ensure pooled connections re-prepare their statements after a reset, prepared statements are per-session.
-- Prepare the statement before executing it.
PREPARE monthly_report AS SELECT 1;
EXECUTE monthly_report;For this error
See this error live on the server
Run these against the affected instance to confirm the diagnosis before you act.
Prepared statement does not exist is session-local. Inspect pg_prepared_statements on the same pool connection and fix statement lifecycle/name reuse.
Prepared statements in this session
List name, parameter types, origin, and SQL text.
SELECT name, parameter_types, from_sql, prepare_time, statement
FROM pg_prepared_statements
ORDER BY prepare_time;Why it happens
What PostgreSQL is telling you
The mechanism behind the error, grounded in the official manual, not paraphrased.
PostgreSQL 18 Documentation, Appendix A. PostgreSQL Error Codes (Table A.1, Class 26, Invalid SQL Statement Name)
26000 → invalid_sql_statement_nameRead the full section on postgresql.org →
Executing an unprepared statement name
The name 'monthly_report' was never prepared in this session, so EXECUTE raises 'prepared statement monthly_report does not exist'.The session continues normally
EXECUTE failed as a standalone statement, so the session has no transactional state to clear before its next query.Reproduce & verify
A real, single-session PostgreSQL reproduction
A literal transcript of SQL run against a live PostgreSQL instance in an isolated lab. The commands below are exactly what was executed.
- 1EXECUTE a prepared-statement name that has not been PREPAREd in this session.
- 2PostgreSQL looks the name up among the session's prepared statements and finds nothing.
- 3The statement aborts with SQLSTATE 26000.
A worker executed a named statement that a different (or reset) connection had prepared, so it was missing on this session.
-- The error is self-contained in one statement; no schema is required.
SELECT 'no schema needed' AS setup_note;EXECUTE monthly_report;SELECT 'ok' AS session_after_error;What PostgreSQL actually returned
setup_note
------------------
no schema needed
(1 row)ERROR: prepared statement "monthly_report" does not exist session_after_error
---------------------
ok
(1 row)EXECUTE succeeds once the statement is prepared first.
Without this
Before: executing a missing statement aborts
With this, tested
After: prepare then execute
- A second operational test: exact SQL, raw output, measured result, and engineer notes
Card required. Cancel before day 7 and you are not charged.
Runbook to fix this
Runbooks for this incident
Full step-by-step fixes for the condition behind this error: the diagnosis, the exact SQL, and output captured in the lab.
- Diagnose PgBouncer queueing and session-state leaksClients wait in PgBouncer even though PostgreSQL has capacity, or session settings behave inconsistently.Free
- Custom plan versus generic plan in prepared statementsThe sixth run of an unchanged prepared statement is twenty times slower than the fifth.Pro
Connected
Everything this error touches
Every page this SQLSTATE connects to: the concept that explains it, the runbooks that fix it, the parameters you tune to prevent it, and the sibling errors it travels with. All real cross-references. Jump straight in, or open the full interactive map.
Verification
- Last verified
- 2026-07-24 (isolated lab, PostgreSQL 18.4)
- Verification scope
- Verified against PostgreSQL 18.4 in an isolated lab environment
- Audit status
- reviewed
Went further?
Pro unlocks the second lab proof
Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.