DROP ROLE
The DROP ROLE statement removes one or more roles. DROP USER is an alias. A role that still owns objects or holds privileges on them cannot be dropped — transfer ownership (ALTER TABLE ... OWNER TO ...) or revoke the grants first.
Examples
Given a few roles:
Query
CREATE ROLE doc_r1;
CREATE ROLE doc_r2;
CREATE ROLE doc_r3;
CREATE USER doc_u1;Drop one:
Query
DROP ROLE doc_r1;Drop several at once:
Query
DROP ROLE doc_r2, doc_r3;DROP USER works on any role:
Query
DROP USER doc_u1;With IF EXISTS, dropping a missing role is not an error:
Query
DROP ROLE IF EXISTS doc_r1;Without it, it is:
Query
DROP ROLE doc_r1;Result
error db error: ERROR: role "doc_r1" does not existNotes
- Dropping roles requires the
CREATEROLEattribute (or superuser); dropping a superuser role requires superuser. - If the role owns objects or is referenced by grants,
DROP ROLEfails withrole "..." cannot be dropped because some objects depend on it.
See also
- CREATE ROLE — create a role
- ALTER ROLE — change a role's attributes
- REVOKE — remove privileges before dropping a role