Understanding Oracle Database Roles and Permissions

An Oracle role is a named bundle of privileges that you grant to users or to other roles. Create the role in a pluggable database, grant object and system privileges to it, grant the role to users, and audit it with the DBA_* views. Managing access through roles keeps security manageable as users and tables multiply.

I ran every statement in this guide on Oracle AI Database 26ai Free (release 23.26.4) in a Docker container, including the examples from the first version of this post. Several things behaved differently from what that version said, so you will find the real output and the corrections below. The last section lists what I did not test.

Table of Contents

  1. [Understanding Oracle Roles](#understanding-oracle-roles)
  2. [Listing Existing Roles](#listing-existing-roles)
  3. [Checking Role Permissions](#checking-role-permissions)
  4. [Managing Role Grants](#managing-role-grants)
  5. [Best Practices](#best-practices)
  6. [Troubleshooting Common Issues](#troubleshooting-common-issues)

Understanding Oracle Roles

Roles in Oracle are named groups of related privileges that can be granted to users or other roles. They simplify the process of managing security and privileges in large database environments.

Types of Roles:

  • Predefined roles (like CONNECT, RESOURCE)
  • User-created roles
  • Application roles
  • External roles

Do not assume the predefined roles mean what their names suggest. In my database CONNECT contained exactly two system privileges, CREATE SESSION and SET CONTAINER. RESOURCE contained 15 CREATE privileges, such as CREATE TABLE, CREATE VIEW, CREATE PROCEDURE and CREATE SEQUENCE. Neither gives access to anyone else’s data. I read both from DBA_SYS_PRIVS.

I worked in the pluggable database FREEPDB1. Create roles and users in a pluggable database, not in the container root. By default Oracle expects common (root-level) users and roles to start with a prefix (C##). The test image had that prefix setting empty (common_user_prefix showed no value), so a root-level CREATE ROLE succeeded and created a *common* role, and I did not reproduce the error. Check which container you are in with SHOW CON_NAME.

Listing Existing Roles

Let’s start with how to view all roles in your Oracle database. Here are practical examples:

-- List all roles with their basic information
SELECT ROLE, AUTHENTICATION_TYPE, COMMON
FROM DBA_ROLES
ORDER BY ROLE;

Example output for the three roles the first version showed (real output from my database):

ROLE                         AUTHENTICATION_TYPE  COMMON
---------------------------- -------------------- ------
CONNECT                      NONE                 YES
DBA                          NONE                 YES
RESOURCE                     NONE                 YES

The first version showed DBA with PASSWORD authentication and COMMON = NO. That is not what a database returns: DBA is NONE and YES. The query itself returned 107 roles in a fresh pluggable database, all Oracle-supplied. To list only roles that people on your team created, filter on ORACLE_MAINTAINED:

SELECT ROLE, AUTHENTICATION_TYPE
FROM DBA_ROLES
WHERE ORACLE_MAINTAINED = 'N'
ORDER BY ROLE;

For more detailed information:

-- List roles with their authentication requirements
SELECT ROLE,
       PASSWORD_REQUIRED,
       AUTHENTICATION_TYPE,
       COMMON,
       ORACLE_MAINTAINED
FROM DBA_ROLES
ORDER BY ROLE;

For CONNECT, DBA and RESOURCE this returned PASSWORD_REQUIRED = NO, AUTHENTICATION_TYPE = NONE, COMMON = YES and ORACLE_MAINTAINED = Y.

Checking Role Permissions

To effectively manage database security, you need to know what permissions each role has. There is a catch the first version missed: ROLE_TAB_PRIVS and ROLE_SYS_PRIVS only describe roles that you have been granted. As a DBA who did not hold the role, I got no rows. Use the DBA_* views to audit any role:

-- Table privileges granted to a role (any role, needs DBA access)
SELECT GRANTEE, OWNER, TABLE_NAME, PRIVILEGE, GRANTABLE
FROM DBA_TAB_PRIVS
WHERE GRANTEE = 'SALES_ROLE'
ORDER BY TABLE_NAME, PRIVILEGE;

-- System privileges granted to a role
SELECT GRANTEE, PRIVILEGE
FROM DBA_SYS_PRIVS
WHERE GRANTEE = 'SALES_ROLE';

ROLE_TAB_PRIVS still works for roles you hold, which includes roles you created:

-- Check table privileges for a specific role
SELECT PRIVILEGE, TABLE_NAME, GRANTABLE
FROM ROLE_TAB_PRIVS
WHERE ROLE = 'SALES_ROLE'
ORDER BY TABLE_NAME, PRIVILEGE;

Real-world example. I created a schema sales_owner with the two tables, and ran this as that user (it needs CREATE ROLE and owns the tables):

-- Create and grant a custom role for sales department
CREATE ROLE sales_role;
-- Grant specific permissions
GRANT SELECT, INSERT ON sales_transactions TO sales_role;
GRANT UPDATE ON customer_data TO sales_role;
-- Check the granted permissions
SELECT PRIVILEGE, TABLE_NAME
FROM ROLE_TAB_PRIVS
WHERE ROLE = 'SALES_ROLE';

Output:

PRIVILEGE      TABLE_NAME
-------------- ----------------------
INSERT         SALES_TRANSACTIONS
SELECT         SALES_TRANSACTIONS
UPDATE         CUSTOMER_DATA

The same query run as SYSTEM, who did not hold the role, returned no rows selected, while DBA_TAB_PRIVS returned the same three privileges. The statement that created the role also granted it to its creator, with the admin option, which is why the owner could see it.

Managing Role Grants

Understanding who has what roles is crucial for security audits. Here’s how to check role grants:

-- List all role grants
SELECT GRANTEE,
       GRANTED_ROLE,
       ADMIN_OPTION,
       DEFAULT_ROLE
FROM DBA_ROLE_PRIVS
WHERE GRANTEE = 'APP_USER'
ORDER BY GRANTED_ROLE;

Practical example:

-- Create a new application user
CREATE USER app_user IDENTIFIED BY "<a-strong-password>";
-- Grant necessary roles
GRANT connect TO app_user;
GRANT sales_role TO app_user;
-- Verify the grants
SELECT GRANTED_ROLE, ADMIN_OPTION, DEFAULT_ROLE
FROM DBA_ROLE_PRIVS
WHERE GRANTEE = 'APP_USER';

The first version used IDENTIFIED BY password. Oracle accepted the literal word password in my test, which is exactly why you should not copy it. Output of the verify query:

GRANTED_ROLE            ADMIN_OPTION DEFAULT_ROLE
----------------------- ------------ ------------
CONNECT                 NO           YES
SALES_ROLE              NO           YES

Default roles and SET ROLE

DEFAULT_ROLE = YES means the role is switched on at login. Three behaviours surprised me:

  • ALTER USER app_user DEFAULT ROLE NONE; also switches off CONNECT, which carries CREATE SESSION. The next login failed with ORA-01045: Login denied. User APP_USER does not have CREATE SESSION privilege.
  • SET ROLE sales_role; does not add the role: it replaces the set of enabled roles. After it, SESSION_ROLES showed only SALES_ROLE; CONNECT was gone from the session. Use SET ROLE ALL; to re-enable every default role, or list all the roles you need.
  • A role created with IDENTIFIED BY a password was granted with DEFAULT_ROLE = NO, and had to be enabled with SET ROLE secure_role IDENTIFIED BY <password>;.

Best Practices

Role Naming Conventions

  • Use descriptive names (e.g., SALES_ANALYST_ROLE)
  • Include department or application prefix
  • Document role purposes

Permission Management

  • Follow the principle of least privilege
  • Regularly audit role permissions
  • Use role hierarchy effectively

Example of implementing role hierarchy:

-- Create department-level role
CREATE ROLE sales_dept_role;
-- Create specific roles
CREATE ROLE sales_analyst_role;
CREATE ROLE sales_manager_role;
-- Set up hierarchy
GRANT sales_dept_role TO sales_analyst_role;
GRANT sales_analyst_role TO sales_manager_role;

This worked as written. DBA_ROLE_PRIVS listed SALES_DEPT_ROLE under SALES_ANALYST_ROLE and SALES_ANALYST_ROLE under SALES_MANAGER_ROLE. A manager therefore receives everything the analyst and the department role carry. To see every role reachable from one role, use a hierarchical query:

SELECT LEVEL AS lvl, GRANTED_ROLE
FROM DBA_ROLE_PRIVS
START WITH GRANTEE = 'SALES_MANAGER_ROLE'
CONNECT BY PRIOR GRANTED_ROLE = GRANTEE;

For the hierarchy above it returned SALES_ANALYST_ROLE at level 1 and SALES_DEPT_ROLE at level 2. Oracle also blocks loops: GRANT sales_manager_role TO sales_dept_role; failed with ORA-01934: circular role grant detected.

Troubleshooting Common Issues

1. Unable to View Role Information

If you can’t see role information, check your privileges:

-- Check your system privileges
SELECT * FROM SESSION_PRIVS;

For app_user this returned CREATE PROCEDURE, CREATE SESSION and SET CONTAINER. Remember that ROLE_TAB_PRIVS and ROLE_SYS_PRIVS show only roles you hold; for example ROLE_SYS_PRIVS returned the two CONNECT privileges for a user who held CONNECT, and no rows for RESOURCE, which that user did not hold.

2. Role Not Taking Effect

Verify role is enabled:

-- Check enabled roles
SELECT * FROM SESSION_ROLES;

There are three common reasons a granted role does nothing:

  1. The session was already open. I granted a role to a user whose session was open. SESSION_ROLES did not show it, and a query that needed it failed, until the session ran SET ROLE ALL; (or logged in again).
  2. The role is not a default role. See the default roles section above: use SET ROLE, or ALTER USER app_user DEFAULT ROLE ALL;.
  3. PL/SQL does not see role privileges. A user who could query sales_owner.sales_transactions through sales_role created a stored procedure with the same query and got ORA-00942: table or view "SALES_OWNER"."SALES_TRANSACTIONS" does not exist at compile time. After GRANT SELECT ON sales_owner.sales_transactions TO app_user; directly, the procedure compiled and ran. Adding AUTHID CURRENT_USER did not fix the compile error in my test.

3. Missing Permissions

Audit role privileges:

-- Check all privileges granted to a role
SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE = 'YOUR_ROLE';
SELECT * FROM DBA_TAB_PRIVS WHERE GRANTEE = 'YOUR_ROLE';

These are the DBA versions of the ROLE_* queries in the first version of this post, which return nothing for roles you do not hold.

4. A revoked role still works

I revoked sales_role from a user while that user’s session was open. Twelve seconds later the same session still listed SALES_ROLE and still read the table. A new session had lost both. So a revoke takes effect at the next login, not immediately: end the user’s sessions if it must apply now.

Frequently Asked Questions

What is the difference between a role and a privilege in Oracle?

A privilege is a single permission such as SELECT on a table. A role is a named bundle of privileges you grant to users as one unit.

How do I see which roles a user has?

Query DBA_ROLE_PRIVS for a specific user, or SESSION_ROLES for the roles active in your current session.

What is the difference between a default role and a non-default role?

A default role is enabled automatically at login. A non-default role must be turned on with SET ROLE before its privileges apply.

How do I revoke a role from a user?

Run REVOKE role_name FROM username. The change takes effect on the user’s next new session.

Conclusion

Understanding and effectively managing Oracle roles and permissions is crucial for maintaining database security. Most of the surprises in my tests were about who can see what: the ROLE_* views only show roles you hold, and roles do not reach into stored PL/SQL.

Remember to:

  • Audit with the DBA_* views, not the ROLE_* views
  • Regularly review role assignments
  • Document all role changes
  • Follow the principle of least privilege
  • Conduct periodic security audits

What I did not test

  • Oracle versions other than Oracle AI Database 26ai Free 23.26.4; older releases (19c, 21c) may differ.
  • The container-root naming error: the test image allowed root-level roles, so I could not reproduce it.
  • Application roles, external roles, secure application roles, and ALTER USER ... DEFAULT ROLE combinations beyond those shown.
  • RAC, Data Guard, Autonomous Database, and Oracle Database Vault.
  • Invoker’s rights beyond the one AUTHID CURRENT_USER procedure that failed to compile.

Related guides