Skip to main content

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 "doc_r1" does not exist

Notes​

  • Dropping roles requires the CREATEROLE attribute (or superuser); dropping a superuser role requires superuser.
  • If the role owns objects or is referenced by grants in any database, DROP ROLE fails with role "..." cannot be dropped because some objects depend on it and lists the objects that depend on the role. DROP ROLE has no CASCADE.
  • The same holds between concurrent transactions: a DROP ROLE and a transaction that grants to the role or makes it an owner cannot both commit. Whichever commits second fails at COMMIT and changes nothing.

See also​

Syntax​

Syntax