Diagnostic Queries
Symptoms
A CREATE SCHEMA tried to create a schema whose name already exists in the database. PostgreSQL raises SQLSTATE 42P06 (duplicate_schema).
- A schema with that name already exists.
- Schema names are unique within a database.
- Common in re-run migrations.
What the server log shows
ERROR: schema "reporting" already exists
Why PostgreSQL raises this — what the manual says
As the CREATE SCHEMA reference (Description) explains:
A schema with that name already exists in the current database; schema names must be unique per database — choose a different name or add IF NOT EXISTS to skip creation when it already exists.
Schema names are unique within a database. Creating one that already exists collides with the existing schema, so PostgreSQL reports 42P06.
Common causes
- Re-running a migration that creates the schema.
- The schema was created earlier.
- A name clash with an existing schema.
How to fix it
- Use
CREATE SCHEMA IF NOT EXISTSfor idempotency. - Check existence via
\dnorpg_namespace. - Choose a unique schema name.
Related & next steps
Reference: PostgreSQL 18 — CREATE SCHEMA.
Thanks — noted. This helps keep the database accurate.