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:
SQL
CREATE ROLE doc_r1;
CREATE ROLE doc_r2;
CREATE ROLE doc_r3;
CREATE USER doc_u1;Drop one:
SQL
DROP ROLE doc_r1;Drop several at once:
SQL
DROP ROLE doc_r2, doc_r3;DROP USER works on any role:
SQL
DROP USER doc_u1;With IF EXISTS, dropping a missing role is not an error:
SQL
DROP ROLE IF EXISTS doc_r1;Without it, it is:
SQL
DROP ROLE doc_r1;error db error: ERROR: Role with name doc_r1 does not exist!
Notes
- Dropping roles requires the
CREATEROLEattribute (or superuser); dropping a superuser role requires superuser. - If the role owns objects or is referenced by grants in any database,
DROP ROLEfails withCannot drop entry "..." because there are entries that depend on it.and lists the objects that depend on the role.DROP ROLEhas noCASCADE. - The same holds between concurrent transactions: a
DROP ROLEand a transaction that grants to the role or makes it an owner cannot both commit. Whichever commits second fails atCOMMITand changes nothing.
See also
- CREATE ROLE — create a role
- ALTER ROLE — change a role's attributes
- REVOKE — remove privileges before dropping a role
Syntax
Syntax