Deletes a database user account.

Syntax

DROP USER name [ CASCADE ]

Description

You can use the DROP USER command to drop the specified user. To drop a superuser, you must be a superuser or have the CREATEROLE privilege.

You cannot delete the user that is still referenced in a database of the cluster. Otherwise, an error occurs. Before dropping a user, you must drop all the objects that belong to the user or reassign their ownership, and revoke the privileges granted by the user.

However, you do not need to delete role memberships involving the user. DROP USER automatically revokes the memberships of the target user in other roles and those of other roles in the target user. Other roles are not dropped or affected.

In addition, if all objects owned by the user belong to a schema that is owned by the user and has the same name as the user, you can specify a CASCADE option. In this case, only the superuser and the name user can issue the DROP USER name CASCADE command, and the schema and all objects in the schema are deleted.

Parameters

ParameterDescription
Parameter Description
name The name of the user to be deleted.
CASCADE Specifies that the schema that is owned by the user and has the same name as the user is dropped when no dependencies on the user or the schema exist. All objects owned by the user in the schema are also dropped.

Examples

Drop a user that does not own objects and is not granted privileges on other objects:

DROP USER john;

Drop the john user that is not granted privileges on the objects, and do not own objects outside of the john schema:

DROP USER john CASCADE;