Diagnostic Queries
Symptoms
A CREATE ROLE/CREATE USER tried to create a role whose name already exists. PostgreSQL raises SQLSTATE 42710 (duplicate_object).
- A role with that name already exists.
- Roles are cluster-wide (shared across databases).
- Common in idempotent provisioning scripts.
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
- Re-running a provisioning script that creates the role.
- The role was created earlier (roles are cluster-wide).
- A name clash with a pre-existing role.
How to fix it
- Skip creation if it exists: check
pg_rolesor useDO/conditional logic. - Use
CREATE ROLE …only when absent; otherwiseALTER ROLEto adjust. - Choose a unique role name.
Related & next steps
Reference: PostgreSQL 18 — CREATE ROLE.
Thanks — noted. This helps keep the database accurate.