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:

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 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, DROP ROLE fails with role "..." cannot be dropped because some objects depend on it.

See also

Syntax

This page contains: