↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / SQL Commands

DROP ROLE

remove a database role

English manual coverage begins with PostgreSQL 6.4. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

anchor
SQL-DROPROLE
file
sql-droprole.html
lang
en
name
DROP ROLE
purpose
remove a database role
purpose zh
移除一个数据库角色
sections same as
Unknown
slug
18
synopsis html
DROP ROLE [ IF EXISTS ] <em class="replaceable"><code>name</code></em> [, ...]
synopsis text
DROP ROLE [ IF EXISTS ] name [, ...]

Syntax

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

Read left to right. Branches are choices, bypasses are optional, loops repeat. Select an underlined parameter to open its rule.

DROP ROLE IF EXISTS name ,

Definition PG 18

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

Description

DROP ROLE removes the specified role(s). To drop a superuser role, you must be a superuser yourself; to drop non-superuser roles, you must have CREATEROLE privilege and have been granted ADMIN OPTION on the role.

A role cannot be removed if it is still referenced in any database of the cluster; an error will be raised if so. Before dropping the role, you must drop all the objects it owns (or reassign their ownership) and revoke any privileges the role has been granted on other objects. The REASSIGN OWNED and DROP OWNED commands can be useful for this purpose; see Section 21.4 for more discussion.

However, it is not necessary to remove role memberships involving the role; DROP ROLE automatically revokes any memberships of the target role in other roles, and of other roles in the target role. The other roles are not dropped nor otherwise affected.

Parameters

IF EXISTS

Do not throw an error if the role does not exist. A notice is issued in this case.

name

The name of the role to remove.

Notes

PostgreSQL includes a program dropuser that has the same functionality as this command (in fact, it calls this command) but can be run from the command shell.

Examples

To drop a role:

DROP ROLE jonathan;

Compatibility

The SQL standard defines DROP ROLE, but it allows only one role to be dropped at a time, and it specifies different privilege requirements than PostgreSQL uses.

See Also

CREATE ROLE, ALTER ROLE, SET ROLE

Compare versions

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · wiki-repair-20261023:a39e55a72808de20046c55f708e94f1393a4db067203dd889744f7078c987512

Text language: en · wiki-repair-20261023:a39e55a72808de20046c55f708e94f1393a4db067203dd889744f7078c987512