0P000
PostgreSQLERRORNotableInvalid Role SpecificationHIGH confidence

invalid role specification

What this means

SQLSTATE 0P000 is raised when a role name specified in a command does not exist in the database cluster. This commonly occurs in GRANT, REVOKE, ALTER, SET ROLE, or connection parameters.

Why it happens
  1. 1GRANT or REVOKE specifying a role name that does not exist
  2. 2SET ROLE to a role the current session user is not a member of
  3. 3CREATE TABLE ... OWNER specifying a non-existent role
How to reproduce

Granting privileges to a role that does not exist.

trigger — this will error
trigger — this will error
GRANT SELECT ON employees TO nonexistent_role;

expected output

ERROR:  role "nonexistent_role" does not exist

Fix 1

Create the role before referencing it

WHEN When the role is new and has not been created yet.

Create the role before referencing it
CREATE ROLE analyst;
GRANT SELECT ON employees TO analyst;

Why this works

Creating the role first ensures it exists in pg_roles before privilege commands reference it.

Fix 2

List existing roles to confirm the correct name

WHEN When a typo or naming convention mismatch is suspected.

List existing roles to confirm the correct name
SELECT rolname FROM pg_roles ORDER BY rolname;

Why this works

Querying pg_roles shows all roles in the cluster; use the exact name in subsequent GRANT commands.

Sources
Official documentation ↗

Class 0P — Invalid Role Specification

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors