Back to Supabase

How To Delete A Role In Postgres 8 AvxY

apps/docs/content/troubleshooting/how-to-delete-a-role-in-postgres-8-AvxY.mdx

1.26.041.1 KB
Original Source

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:

sql
GRANT <role> TO "postgres";

Then you must reassign any objects owned by role:

sql
REASSIGN OWNED BY <role> TO postgres;

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

sql
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:

sql
DROP role <role>;

If you encounter any issues, create a support ticket