How to delete a role in Postgres
Last edited: 2/21/2025
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:
1GRANT <role> TO "postgres";
Then you must reassign any objects owned by role:
1REASSIGN OWNED BY <role> TO postgres;
Once ownership is transferred, you can run the following query:
1DROP 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:
1DROP role <role>;
If you encounter any issues, create a support ticket