# 42P06 — Duplicate schema

> PostgreSQL SQLSTATE 42P06: Duplicate schema (duplicate_schema), source-backed diagnosis and recovery guidance.
---

# 42P06 — Duplicate schema

## At a glance {#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.

<!-- BEGIN SQLSTATE FACTS: generated by scripts/generate.py; do not edit -->

| 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 | `—` |

<!-- source facts: data/errcodes/42P06.json -->
<!-- END SQLSTATE FACTS -->

## Meaning {#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 {#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 {#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 {#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 {#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 {#related}

- [`42P07`](../42p07/)
- [`42P04`](../42p04/)
- [`42939`](../42939/)

## Sources {#sources}
- `src.errcodes.42P06.18.6` — `src/backend/utils/errcodes.txt` line 382, fixed at `724edf9bde9d356724ad384a2e196edc3c9f80f7`; SHA-256 `6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba` ([source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L382)).

- `src.call.42P06.4d5505b63e38ef1b25836623` — `src/backend/catalog/pg_namespace.c` lines 62-64, fixed at `724edf9bde9d356724ad384a2e196edc3c9f80f7`; SHA-256 `89675ba1bb9c531ab4f43db8a6f7cac00956561b342e42ea6eaae6b8d0b50d78` ([source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/catalog/pg_namespace.c#L62-L64)).
- `src.call.42P06.373538bec86ad8eedfce8d7a` — `src/backend/commands/schemacmds.c` lines 132-135, fixed at `724edf9bde9d356724ad384a2e196edc3c9f80f7`; SHA-256 `5fd5f43dce5f36f06ed390014c06f244564072227d25a22735f594d2170626b1` ([source](https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/commands/schemacmds.c#L132-L135)).
- `src.calls.REL_18_6.42P06` — resolved core call groups; SHA-256 `9ee8a0e81d8f0825c5c1ae45583439859a26e602bdd4ce2f2a62aa278867ccbf`.
- [`authored evidence`](../data/evidence/42p06.json) — source claims, message roles, and runtime boundary.
