Skip to content

DROP ROLE

Drop one or more roles or users from the database.

DROP ROLE [ IF EXISTS ] name [, ...]

ROLE and USER are synonymous keywords in this command.

The ability to run DROP ROLE commands requires the system-level DROP ANY ROLE privilege. See ON SYSTEM.

Examples

For example:

premdb=# drop role alex, vicky, henry, niklas;
DROP ROLE

You cannot drop roles that have dependencies in any of your databases. Before dropping a role, drop all the objects it owns (or reassign their ownership) and revoke any privileges the role has been granted on other objects. See the DROP OWNED command. For example:

premdb=# drop role allqa;
ERROR:  role "allqa" cannot be dropped because some objects depend on it
DETAIL:  owner of database alexdb

When you use the IF EXISTS option, the command does not return a warning if the role does not exist.

premdb=# create role bobr;
CREATE ROLE
premdb=# drop role bobr;
DROP ROLE
premdb=# drop role if exists bobr;
DROP ROLE

Parent topic:SQL Commands