42710ERRORTier 1 — Safe✅ HIGH confidenceduplicate object
What this means
A CREATE statement attempted to create a database object (role, schema, extension, trigger, etc.) that already exists. Unlike 42P07 which is specific to relations, 42710 covers a wider set of non-relation object types.
Why it happens
- 1Running CREATE ROLE, CREATE SCHEMA, or CREATE EXTENSION when the object already exists
- 2Migration scripts run multiple times without idempotency checks
- 3CREATE TRIGGER with a name that already exists on the same table
- 4Installing an extension that was already installed in the database
How to reproduce
CREATE ROLE is run twice for the same role name.
CREATE ROLE appuser LOGIN PASSWORD 'secret';
CREATE ROLE appuser LOGIN PASSWORD 'secret'; -- triggers 42710Fix 1: Use IF NOT EXISTS to make creation idempotent
In migration scripts or setup scripts that may be re-run.
CREATE ROLE IF NOT EXISTS appuser LOGIN PASSWORD 'secret';
CREATE SCHEMA IF NOT EXISTS myapp;
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";Why this works
IF NOT EXISTS causes the DDL statement to check the catalog for an existing object with the same name before attempting creation. If found, the statement is a no-op (returns a NOTICE instead of an error). This is a catalog-level check, not a lock-free operation.
What not to do
Drop and recreate the object to avoid the error in production
Why it's wrong: DROP CASCADE removes dependent objects silently; recreating a role loses all its ACL grants.
Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
📚 Feature docs: https://www.postgresql.org/docs/current/sql-createrole.html
Confidence assessment
✅ HIGH confidence
Well-documented. IF NOT EXISTS support varies by object type; most DDL statements added IF NOT EXISTS support in Postgres 9.3–9.5. Verify that the specific object type supports it before relying on it.
See also
🔗 Related errors
📄 Reference pages