role “…” already exists

SQLSTATE 42710 condition duplicate_object class 42 — Syntax Error or Access Rule Violation severity ERROR
Reproduced & verified on PostgreSQL 14.23, 15.18, 16.14, 17.10 and 18.4 — identical message on every version.
Last reviewed 30 May 2025 · Reproduced live with the SQL on this page.

Symptoms

A CREATE ROLE/CREATE USER tried to create a role whose name already exists. PostgreSQL raises SQLSTATE 42710 (duplicate_object).

What the server log shows

ERROR:  role "app_user" already exists

Why PostgreSQL raises this — what the manual says

As the CREATE ROLE reference (Description) explains:

A role with that name already exists; role names must be unique across the entire cluster, so choose a different name or use ALTER ROLE to modify the existing one.

Role names are unique cluster-wide. Creating one that already exists collides with the existing role, so PostgreSQL reports 42710.

Common causes

How to fix it

  1. Skip creation if it exists: check pg_roles or use DO/conditional logic.
  2. Use CREATE ROLE … only when absent; otherwise ALTER ROLE to adjust.
  3. Choose a unique role name.

Related & next steps

Reference: PostgreSQL 18 — CREATE ROLE.