Complete Oracle User Management Documentation
Complete Oracle User Management Documentation
User management encompasses all activities related to defining who can connect to the
database and what actions they can perform once connected. It's crucial for:
● Security: Preventing unauthorized access to sensitive data and operations.
● Data Integrity: Protecting data from accidental or malicious corruption.
● Compliance: Meeting regulatory requirements (e.g., SOX, HIPAA, GDPR) for data
access control and auditing.
● Accountability: Linking specific actions to specific users for auditing and troubleshooting.
Authentication vs. Authorization:
● Authentication: The process of verifying the identity of a user. "Who are you?" (e.g.,
checking username and password).
● Authorization: The process of determining what actions an authenticated user is
permitted to perform. "What are you allowed to do?" (e.g., read a table, create a user,
delete data).
Understanding these core concepts is essential for effective Oracle user management:
● Users:
○ Also known as database accounts or schemas.
○ A user is a logical entity that can connect to the database.
○ Each user typically owns a schema, which is a logical collection of database objects
(tables, views, procedures, etc.). The schema name is usually the same as the
username.
○ Users are authenticated to prove their identity.
● Roles:
○ A named collection of related privileges.
○ Roles are a best practice for managing privileges because they simplify
administration. Instead of granting individual privileges to many users, you grant
privileges to a role, and then grant the role to users.
○ This makes it easier to add or remove privileges for groups of users and simplifies
auditing.
○ Examples: DBA, CONNECT, RESOURCE (system-defined roles);
APP_READ_ONLY, APP_DEVELOPER (user-defined roles).
● Privileges:
○ Specific permissions that allow a user or role to perform a certain action.
○ System Privileges: Allow users to perform database-wide actions or actions on
any object of a certain type (e.g., CREATE SESSION to connect, CREATE TABLE
to create tables, SELECT ANY TABLE to query any table in the database).
○ Object Privileges: Allow users to perform actions on specific database objects
(e.g., SELECT on EMPLOYEES table, EXECUTE on CALCULATE_SALARY
procedure, INSERT on ORDERS table).
● Profiles:
○ A set of limits on database resources and password management policies for users.
○ They control aspects like:
■ Maximum number of concurrent sessions.
■ CPU usage per session/call.
■ Logical I/O per session/call.
■ Idle time and connect time limits.
■ Password complexity, expiry, reuse, and lockout policies.
○ Every user is assigned a profile (explicitly or implicitly, using the DEFAULT profile).
● Schemas:
○ A logical collection of database objects (tables, views, sequences, procedures, etc.)
owned by a database user.
○ When you create a user, Oracle automatically creates a schema with the same
name as the user.
○ The user is the schema owner and has full control over the objects within their
schema.
● Authentication Methods: Oracle supports various ways to authenticate users:
○ Database Authentication: The most common method, where Oracle stores and
verifies the username and password internally.
○ Operating System Authentication: Users are authenticated by the operating
system, and Oracle trusts the OS authentication. Often used for OS users that need
to administer the database (e.g., sys, system).
○ External Authentication (LDAP, Kerberos, RADIUS): Oracle delegates
authentication to an external service like LDAP (e.g., Microsoft Active Directory),
Kerberos, or RADIUS. This provides centralized user management.
○ Enterprise User Security (EUS): A feature that leverages LDAP (specifically
Oracle Internet Directory or third-party LDAP servers) to manage database users
and their roles centrally across multiple databases.
Syntax Breakdown:
● username: The name of the new database user.
● IDENTIFIED BY password: The most common method. Specifies a password for
database authentication. Passwords are case-sensitive by default from Oracle 11g
onward.
● IDENTIFIED EXTERNALLY: For operating system authenticated users. The database
trusts the operating system to verify the user's identity. (e.g., OPS$OS_USERNAME).
● IDENTIFIED GLOBALLY AS 'external_name': For externally authenticated users (e.g., via
LDAP/EUS). external_name is typically the Distinguished Name (DN) from the directory
service.
● DEFAULT TABLESPACE tablespace_name: Specifies the default tablespace where
objects created by this user (if no tablespace is specified) will be stored. If omitted, the
database's default permanent tablespace is used.
● TEMPORARY TABLESPACE temp_tablespace_name: Specifies the temporary
tablespace for the user's temporary segments (e.g., for sorting operations). If omitted, the
database's default temporary tablespace is used.
● QUOTA { integer [K | M | G] | UNLIMITED } ON tablespace_name: Grants storage quota
to the user in a specific tablespace.
○ integer [K | M | G]: A specific size in Kilobytes, Megabytes, or Gigabytes.
○ UNLIMITED: Allows the user to consume any amount of space in the specified
tablespace. This is generally discouraged for application users.
● PROFILE profile_name: Assigns a specific profile to the user, controlling resource limits
and password policies. If omitted, the DEFAULT profile is assigned.
● PASSWORD EXPIRE: Forces the user to change their password upon their first
successful login.
● ACCOUNT LOCK | UNLOCK: Specifies the initial state of the user's account. LOCK
prevents the user from logging in immediately. UNLOCK (default) allows immediate login.
Examples:
1. Basic User Creation (Database Authenticated):
CREATE USER myappuser IDENTIFIED BY MySecureP@ssw0rd;
Note: This user can log in but has no privileges yet.
2. User with Tablespaces and Profile:
CREATE USER hr_user IDENTIFIED BY HR_P@ssw0rd123
DEFAULT TABLESPACE users_data
TEMPORARY TABLESPACE temp_data
QUOTA 100M ON users_data
PROFILE app_user_profile
PASSWORD EXPIRE;
This user gets 100MB quota on users_data tablespace and must change their password
on first login.
3. OS Authenticated User:
CREATE USER OPS$DBADMIN IDENTIFIED EXTERNALLY;
The OS user DBADMIN (on Linux/Unix) or DOMAIN\DBADMIN (on Windows) can now
connect without a password, provided OS_AUTHENT_PREFIX is set correctly in init.ora
or spfile (default is OPS$).
4. Globally Authenticated User (EUS/LDAP):
CREATE USER myldapuser IDENTIFIED GLOBALLY AS
'CN=myldapuser,OU=Users,DC=example,DC=com'
DEFAULT TABLESPACE users_data;
2. Lock an Account:
ALTER USER hr_user ACCOUNT LOCK;
The user hr_user can no longer log in.
3. Unlock an Account:
ALTER USER hr_user ACCOUNT UNLOCK;
Oracle provides several data dictionary views to query information about users.
Key Data Dictionary Views:
● DBA_USERS: Shows all users in the database, visible only to users with SELECT ANY
DICTIONARY privilege or DBA role.
● ALL_USERS: Shows all users accessible to the current user (typically, all users in the
database).
● USER_USERS: Shows information about the current connected user.
● V$SESSION: Dynamic performance view showing information about active user sessions.
Queries to Retrieve User Details:
1. List all users and their default/temporary tablespaces, profiles, and account status:
SELECT
username,
account_status,
default_tablespace,
temporary_tablespace,
profile,
created
FROM
dba_users
ORDER BY
username;
2. Check password expiry status for all users:
SELECT
username,
account_status,
expiry_date
FROM
dba_users
WHERE
account_status LIKE '%EXPIRED%' OR expiry_date IS NOT NULL
ORDER BY
username;
3. Managing Roles
Roles are a cornerstone of Oracle's security model, enabling efficient privilege management by
grouping related privileges.
A role is a named collection of privileges (system privileges, object privileges, or even other
roles) that can be granted to users or other roles.
Benefits of Using Roles:
● Simplified Administration: Instead of granting the same 10 privileges to 50 users
individually, you grant the 10 privileges to one role, and then grant that role to 50 users.
● Centralized Privilege Management: To change privileges for a group of users, you
modify the role, and the changes automatically apply to all users assigned that role.
● Improved Security: Reduces the chance of errors when assigning privileges.
● Easier Auditing: Easier to see what privileges a user has by examining their assigned
roles.
System-defined vs. User-defined Roles:
● System-Defined Roles: Oracle provides several built-in roles, such as:
○ CONNECT: Basic connectivity (CREATE SESSION privilege).
○ RESOURCE: Allows creation of schema objects (CREATE TABLE, CREATE
SEQUENCE, etc.).
○ DBA: Extensive system privileges, typically granted to DBAs.
○ SCHEDULER_ADMIN: Privileges for managing the database scheduler.
○ And many more for specific features (e.g., EM_EXPRESS_ALL, PDB_DBA).
● User-Defined Roles: Roles created by database administrators to group privileges
specific to an application or job function (e.g., APP_DEVELOPER, SALES_ANALYST,
HR_CLERK).
Syntax Breakdown:
● role_name: The name of the new role.
● NOT IDENTIFIED: The most common type. The role is activated automatically when
granted to a user.
● IDENTIFIED BY password: The role requires a password to be explicitly enabled by the
user using SET ROLE role_name IDENTIFIED BY password;. This is less common for
general application roles.
● IDENTIFIED EXTERNALLY: The role is enabled if the operating system authenticates the
user for that role.
● IDENTIFIED GLOBALLY: The role is enabled if an external directory service (like
LDAP/EUS) authenticates the user for that role.
Examples:
1. Basic Role (Not Identified):
CREATE ROLE app_read_only;
Examples:
1. Grant System Privileges to a Role:
GRANT CREATE SESSION, CREATE TABLE, CREATE VIEW TO app_read_only;
This role can now connect, create tables, and create views.
2. Grant Object Privileges to a Role:
GRANT SELECT, INSERT, UPDATE, DELETE ON hr.employees TO
app_read_only;
GRANT EXECUTE ON app_pkg.calculate_salary TO app_read_only;
The role can now perform DML operations on hr.employees and execute the
calculate_salary procedure.
Roles can be granted to users or even to other roles, allowing for a hierarchical privilege
structure.
Syntax:
GRANT role_name [, role_name, ...] TO { user_name | role_name | PUBLIC
} [WITH ADMIN OPTION];
Syntax Breakdown:
● user_name: The user to whom the role is granted.
● role_name: Another role to which the current role is granted (role nesting).
● PUBLIC: Grants the role to all users in the database. Use with extreme caution as it
grants wide access.
● WITH ADMIN OPTION: If specified, the grantee (user or role) can then:
○ Grant the role to other users or roles.
○ Revoke the role from other users or roles.
○ Alter the role (e.g., change password).
○ Drop the role.
○ This option should be used sparingly and only for trusted administrators.
Examples:
1. Grant a Role to a User:
GRANT app_read_only TO myappuser;
myappuser now inherits all privileges granted to app_read_only.
2. Grant a Role to Another Role (Nesting):
CREATE ROLE app_developer;
GRANT app_read_only TO app_developer;
GRANT CREATE PROCEDURE, CREATE TRIGGER TO app_developer;
GRANT app_developer TO dev_user; -- dev_user gets all privileges
from both roles
Examples:
1. Revoke a System Privilege from a Role:
REVOKE CREATE TABLE FROM app_read_only;
Examples:
1. Revoke a Role from a User:
REVOKE app_read_only FROM myappuser;
myappuser loses all privileges associated with app_read_only.
2. Revoke a Role from another Role:
REVOKE app_read_only FROM app_developer;
Data dictionary views provide details about roles and their assignments.
Key Data Dictionary Views:
● DBA_ROLES: Lists all roles in the database.
● DBA_ROLE_PRIVS: Shows roles granted to users and other roles.
● ROLE_ROLE_PRIVS: Shows roles granted to other roles.
● ROLE_SYS_PRIVS: Shows system privileges granted to roles.
● ROLE_TAB_PRIVS: Shows object privileges granted to roles.
● USER_ROLE_PRIVS: Shows roles granted to the current user.
● USER_SYS_PRIVS: Shows system privileges granted directly to the current user (not via
roles).
● USER_TAB_PRIVS: Shows object privileges granted directly to the current user (not via
roles).
Queries to Inspect Role Assignments and Privileges:
1. List all roles in the database:
SELECT role FROM dba_roles ORDER BY role;
4. Managing Privileges
Privileges are the specific permissions that allow users or roles to perform actions in the
database. While it's best practice to grant privileges to roles and then grant roles to users, you
can also grant privileges directly to users.
● System Privileges:
○ Allow users to perform specific database operations or actions on any object of a
specific type.
○ There are over 200 system privileges in Oracle.
○ Examples:
■ CREATE SESSION: Allows a user to connect to the database. (Most basic
privilege for any user).
■ CREATE TABLE: Allows a user to create tables in their own schema.
■ CREATE ANY TABLE: Allows a user to create tables in any schema.
(Powerful, use with caution).
■ SELECT ANY TABLE: Allows a user to query any table or view in the
database. (Very powerful).
■ UNLIMITED TABLESPACE: Allows a user to use an unlimited amount of
space in any tablespace, bypassing quotas. (Generally granted to DBAs
only).
■ ALTER DATABASE, ALTER SYSTEM, GRANT ANY PRIVILEGE.
● Object Privileges:
○ Allow users to perform actions on specific database objects that they do not own.
○ Examples for a TABLE or VIEW:
■ SELECT: Query data from the table/view.
■ INSERT: Add new rows.
■ UPDATE: Modify existing rows. (Can specify columns:
UPDATE(column_name)).
■ DELETE: Remove rows.
■ REFERENCES: Create foreign key constraints referencing the table.
■ ALTER: Alter the table definition (add/drop columns).
■ INDEX: Create an index on the table.
■ READ: (For 12cR2+ tables/views) A restricted form of SELECT, only for
specific types of data.
○ Examples for a SEQUENCE:
■ SELECT: Query NEXTVAL or CURRVAL.
■ ALTER: Alter the sequence.
○ Examples for a PROCEDURE, FUNCTION, PACKAGE:
■ EXECUTE: Run the procedure/function or package.
○ Examples for a DIRECTORY:
■ READ: Read files in the directory.
■ WRITE: Write files in the directory.
While not recommended for general application users (roles are preferred), you can grant
privileges directly. This is sometimes done for specific administrative accounts or during
development.
Syntax:
GRANT { system_privilege | object_privilege_list }
TO { user_name | PUBLIC } [WITH ADMIN OPTION | WITH GRANT OPTION];
Syntax Breakdown:
● user_name: The user receiving the privilege.
● PUBLIC: Grants the privilege to all users in the database. Use PUBLIC with extreme
caution and only for truly universal access (e.g., SELECT on DUAL).
● WITH ADMIN OPTION (for System Privileges only):
○ Allows the grantee (the user receiving the privilege) to grant this system privilege to
other users or roles.
○ Allows the grantee to revoke this system privilege from other users or roles.
○ Allows the grantee to grant any role that has this system privilege to other users or
roles.
○ Warning: Granting system privileges with ADMIN OPTION should be reserved for
very trusted administrators, as it can escalate privileges quickly.
● WITH GRANT OPTION (for Object Privileges only):
○ Allows the grantee to grant this object privilege to other users or roles.
○ Cascading Revokes: If a privilege was granted WITH GRANT OPTION and then
later revoked, any grants made by the grantee based on that privilege will also be
automatically revoked (cascading revoke). This can have unintended
consequences.
Examples:
1. Grant CREATE SESSION directly to a user:
GRANT CREATE SESSION TO temp_user;
Impact of Revoking:
● When a system privilege granted WITH ADMIN OPTION is revoked, any grants made by
the grantee for that specific system privilege are also revoked (cascading revoke).
● When an object privilege granted WITH GRANT OPTION is revoked, any grants made by
the grantee for that specific object privilege are also revoked (cascading revoke).
Examples:
1. Revoke CREATE SESSION from a user:
REVOKE CREATE SESSION FROM temp_user;
Data dictionary views are essential for auditing and understanding privilege assignments.
Key Data Dictionary Views:
● DBA_SYS_PRIVS: Shows all system privileges granted to users and roles.
● DBA_TAB_PRIVS: Shows all object privileges granted to users and roles.
● ALL_TAB_PRIVS: Shows object privileges on objects accessible to the current user.
● USER_SYS_PRIVS: Shows system privileges granted directly to the current user.
● USER_TAB_PRIVS: Shows object privileges granted directly to the current user.
Queries to See Granted System and Object Privileges:
1. List all system privileges granted directly to a specific user (e.g., TEMP_USER):
SELECT
privilege,
admin_option
FROM
dba_sys_privs
WHERE
grantee = 'TEMP_USER'
ORDER BY
privilege;
2. List all object privileges granted directly to a specific user (e.g., TEMP_USER):
SELECT
owner,
table_name,
privilege,
grantor,
grantable
FROM
dba_tab_privs
WHERE
grantee = 'TEMP_USER'
ORDER BY
owner, table_name, privilege;
5. Managing Profiles
Profiles in Oracle Database allow administrators to control resource consumption and enforce
password policies for users.
A profile is a named set of resource limits and password parameters. When a user is assigned a
profile, these limits and policies apply to that user's sessions.
Purpose of Profiles:
● Resource Limits: Prevent a single user or application from monopolizing database
resources (CPU, I/O, memory, connect time). This helps ensure database stability and
performance for all users.
● Password Management: Enforce security policies for user passwords, such as:
○ Password complexity (via verification functions).
○ Password expiration.
○ Minimum password lifetime.
○ Prevention of password reuse.
○ Account locking after too many failed login attempts.
Every database has a DEFAULT profile. If a user is not explicitly assigned a profile during
creation or alteration, they automatically inherit the settings from the DEFAULT profile.
The CREATE PROFILE statement defines a new profile and its parameters.
Syntax:
CREATE PROFILE profile_name LIMIT
{ SESSIONS_PER_USER { integer | UNLIMITED | DEFAULT } }
{ CPU_PER_SESSION { integer | UNLIMITED | DEFAULT } }
{ CPU_PER_CALL { integer | UNLIMITED | DEFAULT } }
{ LOGICAL_READS_PER_SESSION { integer | UNLIMITED | DEFAULT } }
{ LOGICAL_READS_PER_CALL { integer | UNLIMITED | DEFAULT } }
{ IDLE_TIME { integer | UNLIMITED | DEFAULT } }
{ CONNECT_TIME { integer | UNLIMITED | DEFAULT } }
{ PRIVATE_SGA { integer [K | M | G] | UNLIMITED | DEFAULT } } --
12cR2+
{ COMPOSITE_LIMIT { integer | UNLIMITED | DEFAULT } }
{ FAILED_LOGIN_ATTEMPTS { integer | UNLIMITED | DEFAULT } }
{ PASSWORD_LIFE_TIME { integer | UNLIMITED | DEFAULT } }
{ PASSWORD_GRACE_TIME { integer | UNLIMITED | DEFAULT } }
{ PASSWORD_REUSE_TIME { integer | UNLIMITED | DEFAULT } }
{ PASSWORD_REUSE_MAX { integer | UNLIMITED | DEFAULT } }
{ PASSWORD_VERIFY_FUNCTION { function_name | NULL | DEFAULT } }
{ PASSWORD_LOCK_TIME { integer | UNLIMITED | DEFAULT } };
RETURN TRUE;
END;
/
The ALTER PROFILE statement modifies the limits and parameters of an existing profile.
Syntax:
ALTER PROFILE profile_name LIMIT
{ SESSIONS_PER_USER { integer | UNLIMITED | DEFAULT } }
... (all other parameters as in CREATE PROFILE) ...
;
Examples:
1. Increase IDLE_TIME for a profile:
ALTER PROFILE app_user_profile LIMIT IDLE_TIME 60; -- 60 minutes
idle
Syntax Breakdown:
● CASCADE: If there are users currently assigned to the profile being dropped, you must
use CASCADE.
○ When CASCADE is specified, all users who were assigned this profile are
automatically reassigned to the DEFAULT profile.
○ If CASCADE is omitted and users are assigned to the profile, the command will fail.
Examples:
1. Drop a profile with no assigned users:
DROP PROFILE old_test_profile;
The DBA_PROFILES data dictionary view provides details about all profiles and their settings.
Queries to See Profile Settings:
1. List all profiles and their parameters:
SELECT
profile,
resource_name,
resource_type,
limit
FROM
dba_profiles
ORDER BY
profile, resource_name;
● Concept: Oracle trusts the operating system to authenticate the user. If the OS
authenticates a user, Oracle automatically allows them to connect to the database without
requiring a separate database password.
● Mechanism: Oracle looks for a specific prefix (default is OPS$) before the OS username.
For example, if your OS username is oracle and OS_AUTHENT_PREFIX is OPS$,
Oracle will look for a database user named OPS$ORACLE.
● Configuration:
○ Set OS_AUTHENT_PREFIX in init.ora or spfile (e.g., OS_AUTHENT_PREFIX =
'OPS$'). If you set it to "" (empty string), then the OS username directly maps to the
database username.
○ Create the user in the database using IDENTIFIED EXTERNALLY.
● Usage: Primarily used for administrative users (e.g., SYS, SYSTEM) to allow them to
connect even if the database is not fully started or if they forget the password, as long as
they are authenticated at the OS level. Less common for regular application users.
● Example:
1. Ensure OS_AUTHENT_PREFIX is set (e.g., OPS$).
2. CREATE USER OPS$OSUSER_JOHN IDENTIFIED EXTERNALLY;
3. GRANT CREATE SESSION TO OPS$OSUSER_JOHN;
4. From the OS account OSUSER_JOHN, you can connect without a password:
sqlplus / (if sqlplus recognizes the OS user) or sqlplus OPS$OSUSER_JOHN/ (if
sqlplus recognizes the user but you need to specify the user).
● Rule: Grant users and roles only the minimum set of privileges required to perform their
tasks.
● Why: Reduces the attack surface. If an account is compromised, the damage is limited to
what that account is authorized to do.
● Implementation:
○ Avoid granting DBA or SYSDBA unless absolutely necessary.
○ Avoid powerful system privileges like ANY (e.g., SELECT ANY TABLE, DROP ANY
TABLE).
○ Use object-specific privileges over schema-wide or database-wide privileges.
● Rule: Use roles as the primary method for granting and managing privileges. Grant
privileges to roles, and then grant roles to users.
● Why: Simplifies administration, improves consistency, and makes auditing easier.
● Implementation:
○ Define roles that align with job functions (e.g., SALES_ENTRY,
FINANCE_REPORTING, HR_MANAGER).
○ Grant only the necessary system and object privileges to these roles.
○ Grant roles to users.
○ Avoid granting privileges directly to users unless there's a very specific and justified
reason (and document it).
● Rule: Implement comprehensive auditing to track user activities, privilege changes, and
security-related events.
● Why: Provides accountability, helps detect suspicious activity, and aids in forensic
analysis.
● Implementation:
○ Configure AUDIT_TRAIL parameter.
○ Audit critical system privileges (e.g., AUDIT ALL BY user_name BY SESSION
WHENEVER NOT SUCCESSFUL).
○ Audit DML/DDL on sensitive tables (e.g., AUDIT SELECT, INSERT, UPDATE,
DELETE ON hr.employees BY ACCESS).
○ Audit privilege grants/revokes (AUDIT GRANT CONNECT TO SYSTEM).
○ Regularly review audit trails.
● Rule: Define clear policies for when accounts are locked (e.g., inactive, suspicious
activity) and the procedure for unlocking them.
● Why: Prevents unauthorized access through dormant or compromised accounts.
● Implementation:
○ Use IDLE_TIME in profiles to automatically disconnect inactive sessions.
○ Manually ALTER USER ... ACCOUNT LOCK for inactive or suspicious accounts.
○ Have a documented process for users to request account unlocks, involving identity
verification.
● Rule: Periodically (e.g., quarterly, semi-annually) review all user accounts, their assigned
roles, and directly granted privileges.
● Why: Ensures that privileges are still appropriate, identifies dormant accounts, and
removes unnecessary access. Roles can accumulate privileges over time.
● Implementation:
○ Use data dictionary queries (DBA_USERS, DBA_ROLE_PRIVS,
DBA_SYS_PRIVS, DBA_TAB_PRIVS) to generate reports.
○ Involve business owners to validate if users still require specific access levels.
Oracle offers different auditing mechanisms: Standard Auditing, Fine-Grained Auditing (FGA),
and from 12c, Unified Auditing.
8.2.1 Standard Auditing (Pre-12c and still available)
● Enable Auditing: Set the AUDIT_TRAIL initialization parameter in the init.ora file or
spfile.
○ AUDIT_TRAIL = NONE: No auditing (default).
○ AUDIT_TRAIL = OS: Audit records written to an OS file (XML or text).
○ AUDIT_TRAIL = DB: Audit records written to the AUD$ table in the SYS schema.
○ AUDIT_TRAIL = DB_EXTENDED: Like DB, but also captures SQL_TEXT and
SQL_BIND values.
○ AUDIT_TRAIL = XML: Audit records written to an OS XML file.
○ AUDIT_TRAIL = XML, EXTENDED: XML audit with SQL_TEXT and SQL_BIND.
○ Note: After changing AUDIT_TRAIL, the database instance must be restarted.
● AUDIT Statement: Used to specify what to audit.
○ Syntax (System Privileges):
AUDIT { privilege | ALL PRIVILEGES }
[ BY { SESSION | ACCESS } ]
[ WHENEVER [ NOT ] SUCCESSFUL ];
■ BY SESSION: Audits one record per session for the audited event.
■ BY ACCESS: Audits one record for each access or SQL statement. More
granular, more overhead.
■ WHENEVER SUCCESSFUL: Audits only successful operations.
■ WHENEVER NOT SUCCESSFUL: Audits only failed operations (useful for
detecting attacks).
■ (If WHENEVER clause is omitted, both successful and unsuccessful attempts
are audited).
Examples:AUDIT CREATE SESSION WHENEVER NOT SUCCESSFUL; --
Audit failed logins
AUDIT ALTER ANY TABLE BY ACCESS; -- Audit every attempt to
alter any table
AUDIT GRANT ANY PRIVILEGE BY SESSION; -- Audit once per
session when someone grants a privilege
● Define a Clear Auditing Strategy: What needs to be audited for security, compliance,
and troubleshooting?
● Audit Failed Logins: Crucial for detecting brute-force attacks.
● Audit Privilege Grants/Revokes: Track changes to access control.
● Audit DDL Statements: Track schema changes.
● Audit Sensitive Data Access: Use FGA or Unified Auditing policies for compliance.
● Separate Audit Trail from Data: If auditing to DB, ensure the audit tables are in a
separate tablespace (not SYSTEM) to prevent SYSTEM tablespace filling up.
● Regularly Purge Audit Trail: Audit trails can grow very large. Implement a strategy for
archiving and purging old audit data to manage space.
● Secure the Audit Trail: Only highly privileged users (e.g., AUDIT_ADMIN role from 12c)
should have access to audit configuration and the audit trail data.
● Alerting: Integrate audit logs with security information and event management (SIEM)
systems for real-time alerting on critical security events.
Symptoms:
● ORA-28000: the account is locked.
● ORA-28001: the password has expired.
Diagnosis & Resolution:
1. Check Account Status:
SELECT username, account_status, expiry_date FROM dba_users WHERE
username = 'YOUR_USER';
○ If PASSWORD EXPIRE is set in the profile or was explicitly added, the user will be
prompted to change it on first login.
○ Inform the user of the new password and whether they need to change it
immediately.
4. Check Profile Settings: The locking/expiring behavior is often due to the assigned
profile.
SELECT profile FROM dba_users WHERE username = 'YOUR_USER';
SELECT resource_name, limit FROM dba_profiles WHERE profile =
'YOUR_PROFILE' AND resource_type = 'PASSWORD';
Symptoms:
● ORA-01017: invalid username/password; logon denied.
Diagnosis & Resolution:
1. Verify Username: Ensure the user is typing the correct username. Oracle usernames are
case-insensitive by default unless enclosed in double quotes during creation (e.g.,
"MyUser").
2. Verify Password: Passwords are case-sensitive by default from Oracle 11g onward.
Ensure Caps Lock is off.
3. Password Reset: If forgotten, reset the password as shown above:
ALTER USER YOUR_USER IDENTIFIED BY new_password;
Symptoms:
● ORA-01031: insufficient privileges.
○ This is a generic error indicating the user tried to perform an action for which they
do not have the necessary privilege.
Diagnosis & Resolution:
1. Identify the Action: What specific SQL statement or operation was the user trying to
perform?
2. Determine Required Privilege: Consult Oracle documentation or common knowledge for
the privilege needed (e.g., CREATE TABLE, SELECT ON table_name, EXECUTE ON
procedure_name).
3. Check User's Privileges and Roles:
○ Check directly granted system privileges:
SELECT privilege FROM dba_sys_privs WHERE grantee =
'YOUR_USER';
4. Grant Missing Privilege/Role: Grant the necessary privilege to an appropriate role, then
grant the role to the user. Avoid direct grants where possible.
GRANT SELECT ON hr.employees TO app_read_only;
GRANT app_read_only TO YOUR_USER;
5. Role Not Enabled (if role requires password): If a role was created with IDENTIFIED
BY password, the user must explicitly enable it:
SET ROLE role_name IDENTIFIED BY password;
This is less common for general application roles.
Symptoms:
● ORA-01536: space quota exceeded for tablespace 'TABLESPACE_NAME'.
● User cannot create objects or insert data into their schema.
Diagnosis & Resolution:
1. Check User's Quota:
SELECT username, tablespace_name, bytes/1024/1024 current_mb,
max_bytes/1024/1024 max_mb
FROM dba_ts_quotas
WHERE username = 'YOUR_USER' AND tablespace_name =
'TABLESPACE_NAME';
2. Increase Quota:
ALTER USER YOUR_USER QUOTA NEW_SIZE_IN_M ON TABLESPACE_NAME; --
e.g., QUOTA 500M
-- OR, grant unlimited quota (use with caution):
ALTER USER YOUR_USER QUOTA UNLIMITED ON TABLESPACE_NAME;
Symptoms:
● ORA-02391: exceeded simultaneous logins limit (SESSIONS_PER_USER)
● ORA-02392: exceeded session limit for CPU usage (CPU_PER_SESSION)
● ORA-02393: exceeded call limit for CPU usage (CPU_PER_CALL)
● ORA-02394: exceeded session limit on logical reads
(LOGICAL_READS_PER_SESSION)
● ORA-02395: exceeded call limit on logical reads (LOGICAL_READS_PER_CALL)
● ORA-02396: exceeded maximum idle time, please connect again (IDLE_TIME)
● ORA-02399: exceeded maximum connect time, please connect again (CONNECT_TIME)
Diagnosis & Resolution:
1. Identify the Profile and Limit:
SELECT profile FROM dba_users WHERE username = 'YOUR_USER';
SELECT resource_name, limit FROM dba_profiles WHERE profile =
'YOUR_PROFILE';
2. Analyze User Activity: Determine if the user's activity truly warrants hitting the limit or if
there's an inefficient application design or runaway query.
3. Adjust Profile Limit: If the limit is too restrictive for legitimate activity, alter the profile.
ALTER PROFILE YOUR_PROFILE LIMIT IDLE_TIME UNLIMITED; -- or a
higher number
Symptoms:
● ORA-12154: TNS:could not resolve the connect identifier specified.
● ORA-12541: TNS:no listener.
● ORA-12514: TNS:listener does not currently know of service requested in connect
descriptor.
Diagnosis & Resolution (briefly, as this is more Net Services related):
1. Check TNSNames.ora: Ensure the service name in the connection string matches an
entry in tnsnames.ora (client side).
2. Check Listener Status: On the database server, run lsnrctl status to confirm the listener
is running and configured for the correct service.
3. Firewall: Check for firewall rules blocking the database port (default 1521).
4. Network Connectivity: Basic network troubleshooting (ping, telnet to port).
10. Conclusion
Oracle User Management is a cornerstone of database security and operational efficiency. By
mastering the concepts and commands presented in this guide, database administrators can
ensure:
● Secure Access: Only authenticated and authorized individuals can interact with the
database.
● Data Integrity: Protection against unauthorized modifications or deletions of critical data.
● Compliance: Adherence to internal policies and external regulations regarding data
access and auditability.
● Operational Stability: Prevention of resource exhaustion by individual users through
proper profile management.
● Simplified Administration: Efficient management of user privileges through the effective
use of roles.
The emphasis on Role-Based Access Control (RBAC), the Principle of Least Privilege, and
Robust Auditing cannot be overstated. These practices form the bedrock of a secure and
manageable Oracle environment. Regular reviews of user accounts, privilege assignments, and
audit trails are essential to adapt to changing requirements and to proactively identify and
mitigate security risks. Investing time in understanding and implementing these user
management principles will significantly enhance the overall security posture and reliability of
your Oracle databases.