In Oracle Database, managing user privileges is essential for both security and operational efficiency. One powerful tool that helps organize and simplify privilege management is a “role”.
This article is designed for beginners and explains what a role is, how it works, how to create and assign it, and how to use it in real-world scenarios. Text-based diagrams are included to make the concept easy to understand.
What Is a Role?
A role is a named group of privileges that can be granted to users. Instead of granting the same privileges to multiple users individually, you can define a role once and assign it to all users who need those privileges.
Diagram: Role Concept
┌────────────┐
│ Role_A │──→ CREATE TABLE
│ │──→ CREATE VIEW
│ │──→ SELECT ANY TABLE
└────────────┘
↑
│
┌──────┬──────┐
│User X│User Y│ ← Grant Role_A to both
└──────┴──────┘
This centralized approach simplifies privilege management and improves security by limiting direct privilege assignments to users.
Why Use Roles?
Assigning privileges individually to each user can be time-consuming and error-prone. Roles provide the following benefits:
- Centralized privilege management
- Simplified user onboarding
- Easier updates when privileges change
Types of Roles
Oracle defines two types of roles:
| Type | Description |
|---|---|
| System-defined | Predefined roles such as DBA, CONNECT |
| User-defined | Custom roles created by DBAs for specific use |
Common System Roles
| Role Name | Main Privileges Included |
|---|---|
| CONNECT | Basic privileges to connect and create sessions |
| RESOURCE | Privileges to create tables, procedures, triggers, etc. |
| DBA | Full administrative privileges (use with caution) |
Basic Role Operations
1. Create a Role
CREATE ROLE app_user_role;
2. Grant Privileges to the Role
GRANT CREATE TABLE, CREATE VIEW TO app_user_role;
3. Grant the Role to a User
GRANT app_user_role TO user_a;
4. Drop a Role
DROP ROLE app_user_role;
How to Check Role Information
List all defined roles:
SELECT * FROM dba_roles;
Check roles granted to a specific user:
SELECT * FROM dba_role_privs WHERE grantee = 'USER_A';
Use Case: Assigning a Developer Role
Suppose you want to grant the same set of privileges to multiple developers. You can define a role called dev_role and assign it to each developer:
-- Create the role
CREATE ROLE dev_role;
-- Grant privileges to the role
GRANT CREATE TABLE, CREATE VIEW, SELECT ANY TABLE TO dev_role;
-- Assign role to users
GRANT dev_role TO dev_user1;
GRANT dev_role TO dev_user2;
If you later decide to add more privileges, such as ALTER SESSION, you only need to grant it to the role:
GRANT ALTER SESSION TO dev_role;
All users assigned the role will automatically inherit the new privilege.
Default Roles and Runtime Role Activation
Oracle allows you to control whether a granted role is active by default or must be explicitly activated.
Granting as Default Role
GRANT dev_role TO dev_user1 DEFAULT ROLE;
Activating Role at Runtime
SET ROLE dev_role;
This flexibility is useful for granting elevated privileges only when needed.
Security Best Practices
- ⚠ Avoid assigning powerful roles (like DBA) to general users
- ⚠ Monitor privileges granted to the
PUBLICrole, as all users inherit them
SELECT * FROM dba_sys_privs WHERE grantee = 'PUBLIC';
Summary
| Item | Description |
|---|---|
| What is a Role | A named set of privileges granted to users |
| Benefits | Simplified, centralized privilege management |
| Types | System roles (e.g., CONNECT), user-defined roles |
| Operations | CREATE ROLE, GRANT, SET ROLE, DROP ROLE, etc. |
| Best Practices | Keep roles granular and privilege-specific |
[reference]
7.2 About User Privileges and Roles

コメント