0P000ERRORTier 2 — Caution✅ HIGH confidenceinvalid 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
- 1GRANT or REVOKE specifying a role name that does not exist
- 2SET ROLE to a role the current session user is not a member of
- 3CREATE TABLE ... OWNER specifying a non-existent role
How to reproduce
Granting privileges to a role that does not exist.
GRANT SELECT ON employees TO nonexistent_role;Fix 1: Create the role before referencing it
When the role is new and has not been created yet.
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 a typo or naming convention mismatch is suspected.
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 docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 0P — Invalid Role Specification
Confidence assessment
✅ HIGH confidence
Standard SQLSTATE. Behaviour consistent across all versions.
See also
📄 Reference pages