42P06 — Duplicate schema
42P06 — Duplicate schema
At a glance
42P06 (duplicate_schema) is a schema-definition collision. Plain CREATE SCHEMA errors; IF NOT EXISTS can emit NOTICE and continue, but that conditional path only skips creation and does not reconcile the existing schema.
| Field | Value |
|---|---|
| SQLSTATE | 42P06 |
| Condition | duplicate_schema |
| Status | active |
| Known present by | 7.4 |
| Locked snapshots | 9.0.23, 9.1.24, 9.2.24, 9.3.25, 9.4.26, 9.5.25, 9.6.24, 10.23, 11.22, 12.22, 13.23, 14.24, 15.19, 16.15, 17.11, 18.6, 19beta3 |
| Macros | ERRCODE_DUPLICATE_SCHEMA |
| Aliases | — |
Meaning
NamespaceCreate reports ERROR schema "%s" already exists when the pg_namespace name lookup finds a row. CREATE SCHEMA IF NOT EXISTS checks the same namespace and reports NOTICE schema "%s" already exists, skipping before creation. Both messages identify the schema itself, not a relation inside it. The fixed command path performs the creation-permission checks before the conditional skip; the NOTICE is not an ownership or definition comparison.
Diagnosis
Resolve the target database and schema, then inspect pg_namespace.nspname, owner/ACL, contents, and the exact migration statement. Preserve severity: NOTICE is conditional behavior and lets the command continue; plain CREATE’s ERROR aborts an explicit transaction. Do not infer that a NOTICE schema has the requested owner, grants, extensions, tables, or migration version.
Response
Reuse only when owner, privileges, and contents meet the application contract. IF NOT EXISTS does not verify or reconcile those properties; follow it with explicit ownership/grant or migration checks when required. Do not drop a schema merely to pass a migration. If plain CREATE produced an ERROR in an explicit transaction, roll back to a suitable savepoint or roll back the transaction before continuing.
Messages
The selected variants are schema "%s" already exists (explicit ERROR) and schema "%s" already exists, skipping (explicit NOTICE). %s is the dynamic schema name; neither message certifies the existing schema’s owner or definition.
Versions
From 7.4 through 18.6 and 19beta3; that catalogue range is not a precise introduction claim. The selected ERROR and NOTICE branches are fixed 18.6 source paths, and runtime was not run.
Related
Sources
-
src.errcodes.42P06.18.6—src/backend/utils/errcodes.txtline 382, fixed at724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-2566e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba(source). -
src.call.42P06.4d5505b63e38ef1b25836623—src/backend/catalog/pg_namespace.clines 62-64, fixed at724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-25689675ba1bb9c531ab4f43db8a6f7cac00956561b342e42ea6eaae6b8d0b50d78(source). -
src.call.42P06.373538bec86ad8eedfce8d7a—src/backend/commands/schemacmds.clines 132-135, fixed at724edf9bde9d356724ad384a2e196edc3c9f80f7; SHA-2565fd5f43dce5f36f06ed390014c06f244564072227d25a22735f594d2170626b1(source). -
src.calls.REL_18_6.42P06— resolved core call groups; SHA-2569ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf. -
authored evidence— source claims, message roles, and runtime boundary.