Postgres DROP ROLE Helper
DROP ROLE fails far more often than it succeeds, because a PostgreSQL role is referenced from three different places: objects it owns, privileges it was granted, and default privileges someone set on its behalf - and all three are recorded per database. The error message names a count, not a list, so people delete grants at random until it works. This generator writes the dependency audit first, then the per-database REASSIGN OWNED and DROP OWNED script in the order that actually clears the dependencies, then the final DROP ROLE, plus a decoder for each DETAIL line you can get back. Everything runs in your browser; no connection details are sent anywhere.
Do more than postgres drop role helper — meet Chat2DB
Chat2DB is an AI-powered SQL client for Windows, macOS and Linux. Write SQL in natural language, format and optimize queries automatically, and manage MySQL, PostgreSQL, Oracle and 20+ other databases in one workspace.
How to use
- Enter the role you want to drop and the role that should inherit its objects, then list every database that role touches.
- Run the audit queries first - the pg_shdepend query tells you exactly which databases still hold dependencies, including ones you forgot about.
- Run the generated script database by database, then DROP ROLE; if it still fails, match the DETAIL line against the troubleshooting panel.
Frequently asked questions
Why does Postgres say "role cannot be dropped because some objects depend on it"?
Because the role is still referenced in the shared pg_shdepend catalogue. There are three separate ways that happens. First, ownership: the role owns a table, view, sequence, function or schema, and dropping it would leave that object without an owner. Second, privileges: someone ran GRANT SELECT ON orders TO the_role, so the role appears in an ACL even though it owns nothing. Third, default privileges: someone ran ALTER DEFAULT PRIVILEGES FOR ROLE the_role, which leaves an entry in pg_default_acl that survives long after the objects are gone. The DETAIL line under the error tells you which kind you hit and, crucially, which database - dependencies are recorded per database, so a role can look clean in the database you are connected to and still be blocked by objects in another one.
What is the difference between REASSIGN OWNED BY and DROP OWNED BY?
REASSIGN OWNED BY old_role TO new_role changes the owner of every object the old role owns in the current database. Nothing is deleted and no data is rewritten; it is a catalogue update that finishes quickly even on large schemas. DROP OWNED BY old_role does two very different things depending on when you run it: if the role still owns objects, those objects are dropped, and with CASCADE anything depending on them goes too. If you have already reassigned, the role owns nothing, so DROP OWNED only removes the role's GRANTs and its default-privilege entries - which is exactly the leftover state that blocks DROP ROLE. That is why the safe sequence is REASSIGN OWNED BY first, then DROP OWNED BY, then DROP ROLE. Running DROP OWNED BY first on a production role is how people lose tables.
I ran REASSIGN OWNED and DROP OWNED but DROP ROLE still fails. What now?
Almost always it is another database. Both statements only act on the database you are connected to, while DROP ROLE checks every database at once, so a single leftover GRANT in a reporting replica or an old staging database is enough to block it. Run the pg_shdepend audit query from any database: it lists every database that still references the role, with deptype 'o' for ownership and 'a' for privileges. Connect to each one that appears and repeat the block. A NULL database in that result means a shared object - a database, a tablespace or a role membership - which REASSIGN OWNED cannot reach; fix those with ALTER DATABASE ... OWNER TO, ALTER TABLESPACE ... OWNER TO, or REVOKE for memberships. When the audit query returns zero rows, DROP ROLE will succeed. Chat2DB shows roles, ownership and grants next to the schema tree, which makes the leftover grant easy to spot: download it at https://chat2db.ai/download or use the web version at https://app.chat2db.ai.
