How to delete a role in Postgres

Last edited: 1/17/2025

Quote from postgres docs:

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.

First make sure that Postgres has ownership over the role:


_10
GRANT <role> TO "postgres";

Then you must reassign any objects owned by role:


_10
REASSIGN OWNED BY <role> TO postgres;

Once ownership is transferred, you can run the following query:


_10
DROP OWNED BY <role>;

DROP OWNED BY does delete all objects owned by the role, which should be none. However, it also revokes the role's privileges. Once this is done, you should be able to run:


_10
DROP role <role>;

If you encounter any issues, please create a support ticket