SQLSTATE 42P05Severity lowLab verified

Incident brief

Duplicate prepared statement

Preparing a statement with a name that is already prepared in the session raises this error; prepared-statement names must be unique per session.

Reproduced on PostgreSQL 18.4Verified 2026-07-24 (isolated lab, PostgreSQL 18.4)Reviewed by Verified against PostgreSQL 18.4 in an isolated lab environment

In 10 seconds

What
Duplicate prepared statement
What triggers it
PREPARE a statement under a given name.
The fix
Use a unique name, or DEALLOCATE the existing statement before re-preparing it.
Proof
Reproduced on PostgreSQL 18.4 → The reproduction prepares a name, then prepares it again: the second PREPARE raises SQLSTATE 42P05.

The fix

What to do right now

The immediate, application-level response to this error.

  • Use a unique name, or DEALLOCATE the existing statement before re-preparing it.
  • In drivers and pools, let the driver manage prepared-statement names or DEALLOCATE ALL on connection reset.
Fix — SQL
-- Prepare each statement name once per session.
PREPARE dup_ps AS SELECT 1;

Related & next steps

Follow the thread

Everything this error touches — jump straight to the sibling error, term, runbook, or parameter.

Verification

PG 18.4
Last verified
2026-07-24 (isolated lab, PostgreSQL 18.4)
Reviewed by
Verified against PostgreSQL 18.4 in an isolated lab environment
Audit status
reviewed