DROP ROLE

A DDL command for removing database roles

DROP ROLE is a DDL command for removing database roles.

DROP ROLE was added in PostgreSQL 8.1, replacing the existing DROP ROLE and DROP GROUP commands (which are retained as aliases of DROP ROLE).

Usage

DROP ROLE removes the specified role from the PostgreSQL instance.

Any objects in the PostgreSQL instance owned by the role must be reassigned or removed before DROP ROLE can be executed.

However, DROP ROLE will succeed regardless of whether any other roles are a member of the role to be dropped.

Change history

Examples

Basic DROP ROLE execution:

postgres=# DROP ROLE foo;
DROP ROLE

Attempting to drop a role which does not exist:

postgres=# DROP ROLE foo;
ERROR:  role "foo" does not exist

Safely attempting to drop a role which might not exist:

postgres=# DROP ROLE IF EXISTS foo;
NOTICE:  role "foo" does not exist, skipping
DROP ROLE

Attempting to drop a role which still owns one or more objects in the current database:

postgres=# DROP ROLE foo;
ERROR:  role "foo" cannot be dropped because some objects depend on it
DETAIL:  owner of database bar
owner of table baz

Attempting to drop a role which still owns one or more objects in a different database in the PostgreSQL instance:

postgres=# DROP ROLE foo;
ERROR:  role "foo" cannot be dropped because some objects depend on it
DETAIL:  1 object in database bar

Categories

DDL, User management

See also

CREATE ROLE, ALTER ROLE