How can I list ALL grants a user received?
The privileges assigned to a MySQL user can be procured using:
Here, replace user@host
with the respective user credentials. In PostgreSQL or Oracle, this can be done by querying their corresponding security catalogs or dictionary views.
In Oracle, you can access system privileges by querying dba_sys_privs
:
Without fail, swap 'USERNAME'
with the genuine username. Account for direct object privileges, role-based privileges, and column privileges for an extensive list.
The "show me everything" approach
Direct system and object permits
System privileges of a user can be retrieved by querying dba_sys_privs
:
Direct grants to tables or views are displayed with the dba_tab_privs
view:
Role-based privileges rock!
Roles also house permissions assigned through them. Thus, fetch the roles linked to a user with:
To know the system privileges related to these roles, use:
Bring it all together
In order to render a composite list of all object grants, bring all_tab_privs_recd
into play:
Do remember, all_tab_privs_recd
might omit temporary table grants.
DBMS_METADATA, my new best friend
Oracle's DBMS_METADATA
package - it's like showing up at a buffet and being handed everything:
Ensure you replace 'USERNAME'
with the actual username (vital note - case-sensitivity!)
Transformation time!
When constructing these queries, mind the duplicate entries. It's like finding clones at a party; ensuring clear, organized results will make everyone happier (and less confused!)
Navigating uncertainties
Drilling down role hierarchy
While exploring role grants, ponder upon the role hierarchy. You can fetch each role's privileges in a recursive manner:
Temporary tables
General views might miss out on temporary table grants. So tune-in to specific views that list these privileges.
Column-specific liberties
For more granularity, DBA_TAB_PRIVS
reveals column-specific privileges:
Ignoring default schemas
To focus more on specific user permissions, eliminate defaults:
Was this article helpful?