SQLSTATE 42710Severity lowLab verified

Incident brief

Duplicate object

A CREATE ROLE named a role that already exists. PostgreSQL refused to create a second role under the same name.

What lands in your log

ERROR: role "reporting_ro" already exists

Reproduced on PostgreSQL 16.14Verified 2026-07-16 (Docker lab, PostgreSQL 16.14)Verified against PostgreSQL 16.14 in an isolated lab environment

In 10 seconds

What triggers it
CREATE ROLE with a name that already exists.
Fix
Wrap the CREATE ROLE in a DO block that catches the duplicate_object exception, for idempotent setup scripts.
Proof
Reproduced on PostgreSQL 16.14 → Creating a role with a name that already existed was rejected with SQLSTATE 42710. Exactly one role with that name still exists afterward.

Fix

What to do right now

Application-level steps for this error.

  • Wrap the CREATE ROLE in a DO block that catches the duplicate_object exception, for idempotent setup scripts.
  • Otherwise, check pg_roles first and only create the role if it's missing.
  • Don't widen the exception handler to WHEN OTHERS, see the counterexample for what that silently hides.
Fix SQL
DO $$ BEGIN
  CREATE ROLE reporting_ro;
EXCEPTION WHEN duplicate_object THEN
  NULL;
END $$;

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.

Open in the interactive map →

Verification

PG 16.14
Last verified
2026-07-16 (Docker lab, PostgreSQL 16.14)
Verification scope
Verified against PostgreSQL 16.14 in an isolated lab environment
Audit status
reviewed
ShareLinkedInX

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.

FollowSubstackLinkedInnew errors · lab notes · hiring loops