PostgreSQL 10 – Fixing ‘Privileges Dependent’ Error When Dropping Role/User

postgresqlpostgresql-10

I had a user/role that was a database owner;

  1. so I dropped first the database;
  2. I try dropping the user and I get the following error:

role 'user_name' cannot be dropped because some objects depend ot it
DETAIL: privileges for schema public

This is very confusing for me;

The schema public is the default schema schema when a database is created.

By dropping the database, shouldn't schema and other objects related to database dropped ? Why this privileges error ?

I want not just a solution to fix it, but also to understand why.

I checked:

  • with \l to be sure the database was droped
  • \du to check role attributes(empty)

Best Answer

PostgreSQL isn't MySQL. You can't drop databases or users without being attached to some database. Based on the error message, the database you are attached to in order to execute the DROP USER statement is the one whose public schema has privileges granted to the doomed user.

Schema grants are not attributes of a role, so don't show up in \du. To see them, you would use \dn+.