Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

PostgreSQL Error 2B000: Dependent Privilege Descriptors

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

PostgreSQL error 2B000 (dependent_privilege_descriptors_still_exist) means you tried to drop a role or object that still has privileges granted on other objects. PostgreSQL blocks the drop until those grants are removed. The fix is to find every dependent privilege, revoke or reassign it, then drop the role or object again.

What You'll Need

  • Superuser access (or a role with CREATEROLE and the ability to revoke privileges owned by others).
  • psql or another SQL client connected to the target database.
  • The exact role name or object name that triggered the error.
  • Access to every database in the cluster, because privileges can exist outside the current database.

Step-by-Step

  1. Read the full error message. It usually names the role and the object type (for example, "role \"alice\" cannot be dropped because some objects depend on it"). Note the role or object name and any detail lines listing privileges.
  2. Connect as a superuser. Run psql -U postgres -d your_database. If you are not superuser, you may not be able to see or revoke grants owned by other roles.
  3. List privileges granted to the role. In each database, run a query against the system catalogs. For example, to find table privileges: SELECT grantee, table_schema, table_name, privilege_type FROM information_schema.role_table_grants WHERE grantee = 'alice'; Replace alice with your role. Also check information_schema.role_usage_grants for schema and sequence usage, and information_schema.role_column_grants for column-level grants.
  4. Check other object types. Privileges can exist on schemas, sequences, functions, procedures, types, databases, tablespaces, and foreign servers. Query pg_class, pg_namespace, pg_proc, pg_type, pg_database, and pg_tablespace for relacl, nspacl, proacl, typacl, datacl, and spcacl entries that include the role. A simpler approach is to use \dp in psql to show privileges for tables, views, and sequences, and \dn+ for schemas.
  5. Revoke each privilege. For every grant found, run the appropriate REVOKE statement. For example: REVOKE SELECT ON TABLE schema.table FROM alice; or REVOKE USAGE ON SCHEMA schema FROM alice;. If the role owns objects, you must reassign ownership first: REASSIGN OWNED BY alice TO new_owner; in each database, then DROP OWNED BY alice; in each database. DROP OWNED removes all privileges and ownership in the current database only, so repeat it in every database.
  6. Repeat across all databases. Connect to each database in the cluster and run the checks and revokes. The error often persists because a grant exists in a database you did not check.
  7. Drop the role or object again. Once no dependencies remain, run DROP ROLE alice; or the original DROP command. If it still fails, re-run the catalog queries to catch anything missed.

Common Mistakes

  • Only checking the current database. Privileges are per-database; a grant in another database will still block the drop.
  • Forgetting ownership. A role that owns objects cannot be dropped until ownership is reassigned or the objects are dropped. REASSIGN OWNED handles this.
  • Revoking from the wrong grantee. Privileges may be granted to a group role that the target role is a member of. Check role membership with \du and revoke from the group if needed.
  • Ignoring default privileges. Default privileges set with ALTER DEFAULT PRIVILEGES can create new grants automatically. Check pg_default_acl and revoke or alter them.
  • Using DROP OWNED in only one database. It is scoped to the current database; run it everywhere.

Tips

  • Use \dp and \dn+ in psql for a quick visual of grants without writing catalog queries.
  • Before dropping a role, run REASSIGN OWNED BY role TO new_owner; then DROP OWNED BY role; in every database. This is the cleanest way to remove all dependencies.
  • If you only need to remove a specific privilege, revoke it directly rather than dropping the role.
  • Keep a record of grants before revoking, in case you need to restore them.
  • Test the drop in a staging environment if possible.

Troubleshooting

If the error persists after revoking visible grants, check for privileges granted to roles that the target role inherits. Use \du to see membership. Also check for grants on large objects, foreign data wrappers, and event triggers. If you cannot find the dependency, query pg_shdepend as superuser: SELECT * FROM pg_shdepend WHERE refobjid = (SELECT oid FROM pg_roles WHERE rolname = 'alice'); This shows shared dependencies across databases. If the role owns objects in a database you cannot access, you may need to connect as a superuser to that database. If you are not superuser, ask your database administrator to perform the revokes or drop.

Frequently Asked Questions

What does error 2B000 mean?

It is PostgreSQL's SQLSTATE for "dependent privilege descriptors still exist." It occurs when you try to drop a role or object that still has privileges granted on other objects.

Can I drop a role without revoking privileges?

No. PostgreSQL requires all dependent privileges and ownership to be removed first. Use REASSIGN OWNED and DROP OWNED in every database.

Does DROP OWNED work across all databases?

No, it only affects the current database. You must run it in each database where the role has objects or privileges.

How do I find all privileges granted to a role?

Query information_schema.role_table_grants, role_usage_grants, and role_column_grants, or use psql commands like \dp and \dn+. Also check pg_shdepend for shared dependencies.

What if I don't have superuser access?

You cannot revoke privileges owned by other roles or see all dependencies. Ask a superuser or the database owner to perform the revokes and drop.

Why does the error mention a specific object?

The error message often includes detail lines naming the object and privilege that depend on the role. Use that information to target your revokes.