Incident brief
Duplicate schema
CREATE SCHEMA fails if a schema of that name already exists; IF NOT EXISTS makes the creation idempotent.
What lands in your log
ERROR: schema "reporting" already exists
In 10 seconds
- What triggers it
- CREATE SCHEMA with a name that already exists.
- 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.
Fix
What to do right now
Application-level steps for this error.
- Add IF NOT EXISTS to make the CREATE SCHEMA idempotent.
- Or check for the schema first and drop it deliberately before recreating.
-- Make the create idempotent with IF NOT EXISTS.
CREATE SCHEMA IF NOT EXISTS reporting;For this error
See this error live on the server
Run these against the affected instance to confirm the diagnosis before you act.
Duplicate schema is resolved from pg_namespace. Check exact spelling/ownership and avoid reserved pg_ prefixes.
Schema names and owners
List existing schemas, including whether the current role can create in them.
SELECT nspname AS schema_name, pg_get_userbyid(nspowner) AS owner,
has_schema_privilege(current_user, oid, 'CREATE') AS can_create
FROM pg_namespace
ORDER BY nspname;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 42, Syntax Error or Access Rule Violation)
42P06 → duplicate_schemaRead the full section on postgresql.org →
Creating a schema that already exists
The schema 'reporting' already exists, so a plain CREATE SCHEMA raises 'schema reporting already exists'.The session continues normally
CREATE SCHEMA failed outside a transaction block, leaving nothing to undo before the next statement runs.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.
- 1CREATE SCHEMA with a name that already exists.
- 2PostgreSQL finds the schema already present.
- 3The statement aborts with SQLSTATE 42P06: 'schema already exists'.
A migration re-ran and CREATE SCHEMA collided with the schema it had created on a previous run.
CREATE SCHEMA reporting;CREATE SCHEMA reporting;SELECT 'ok' AS session_after_error;What PostgreSQL actually returned
CREATE SCHEMAERROR: schema "reporting" already exists session_after_error
---------------------
ok
(1 row)The statement is safe to re-run once it uses IF NOT EXISTS.
Without this
Before: a duplicate CREATE SCHEMA aborts
With this, tested
After: IF NOT EXISTS skips cleanly
- A second operational test: exact SQL, raw output, measured result, and engineer notes
Card required. Cancel before day 7 and you are not charged.
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.