SQLSTATE 42P06Severity lowLab verified

Incident brief

Duplicate schema

CREATE SCHEMA fails if a schema of that name already exists; IF NOT EXISTS makes the creation idempotent.

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 schema
What triggers it
CREATE SCHEMA with a name that already exists.
The fix
Add IF NOT EXISTS to make the CREATE SCHEMA idempotent.
Proof
Reproduced on PostgreSQL 18.4 → A CREATE SCHEMA reproduces SQLSTATE 42P06 on the pre-existing name.

The fix

What to do right now

The immediate, application-level response to this error.

  • Add IF NOT EXISTS to make the CREATE SCHEMA idempotent.
  • Or check for the schema first and drop it deliberately before recreating.
Fix — SQL
-- Make the create idempotent with IF NOT EXISTS.
CREATE SCHEMA IF NOT EXISTS reporting;

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