top of page

Unified Auditing in Oracle Database 23ai — Policies, Column-Level Auditing and Purging Runbook

OmerNarman
Oct 7
5 min read

Updated: Oct 24

Environment used in this runbook:

  • Database: Oracle Database 23ai, PDB PDB1

  • Audited schema: HR

  • Audit administrator: AUD_ADMIN

  • Licensing: Unified Auditing is a core feature, no extra license


What changed in 23ai

  • Traditional auditing (AUDIT_TRAIL, SYS.AUD$, FGA via DBMS_FGA) is desupported. Unified auditing is the only auditing mechanism; databases upgraded to 23ai run in pure unified mode.

  • Column-level auditing is new: audit SELECT (salary) instead of every SELECT on the table.

  • Audit records are written immediately to AUDSYS.AUD$UNIFIED (partitioned, read through UNIFIED_AUDIT_TRAIL), so no more queued writes or flush calls.

  • Predefined policies ORA_SECURECONFIG and ORA_LOGON_FAILURES are enabled out of the box.

Roles: AUDIT_ADMIN (create/enable policies, purge) and AUDIT_VIEWER (read the trail).

Step 1 — Verify the mode and what is already audited

SQL

ALTER SESSION SET CONTAINER = PDB1;

SELECT value FROM v$option WHERE parameter = 'Unified Auditing'; -- TRUE

SELECT policy_name, enabled_option, entity_name, entity_type, success, failure

FROM audit_unified_enabled_policies ORDER BY 1;

SELECT policy_name, audit_option, audit_option_type, object_schema, object_name

FROM audit_unified_policies WHERE policy_name = 'ORA_SECURECONFIG' ORDER BY 2;

Why: know your baseline. ORA_SECURECONFIG already audits DDL on users/roles/profiles, ALTER SYSTEM, GRANT ... ANY, CREATE DATABASE LINK, logons as SYSDBA and more.

Step 2 — Create the audit administrator

SQL

CREATE USER aud_admin IDENTIFIED BY "AudAdmin#2026";

GRANT CREATE SESSION, AUDIT_ADMIN TO aud_admin;

CREATE USER aud_viewer IDENTIFIED BY "AudViewer#2026";

GRANT CREATE SESSION, AUDIT_VIEWER TO aud_viewer;

Why: separation of duties — the DBA who administers the database should not be the one who can disable or purge auditing.

Step 3 — Object-action policy (who touches HR.EMPLOYEES)

SQL

-- as AUD_ADMIN

CREATE AUDIT POLICY hr_emp_dml_pol

ACTIONS SELECT ON hr.employees,

INSERT ON hr.employees,

UPDATE ON hr.employees,

DELETE ON hr.employees

WHEN 'SYS_CONTEXT(''USERENV'',''SESSION_USER'') NOT IN (''HR_BATCH'')' EVALUATE PER SESSION;

AUDIT POLICY hr_emp_dml_pol; -- all users

-- or targeted:

-- AUDIT POLICY hr_emp_dml_pol BY app_user, analyst;

-- AUDIT POLICY hr_emp_dml_pol EXCEPT hr_batch;

-- AUDIT POLICY hr_emp_dml_pol WHENEVER NOT SUCCESSFUL;

Why: the WHEN condition prunes noise (the trusted batch account) and EVALUATE PER SESSION evaluates it once per session instead of per statement. WHENEVER NOT SUCCESSFUL is ideal for "failed access attempts only".

Step 4 — Column-level auditing (new in 23ai)

SQL

CREATE AUDIT POLICY hr_salary_col_pol

ACTIONS SELECT (salary, commission_pct) ON hr.employees,

UPDATE (salary) ON hr.employees;

AUDIT POLICY hr_salary_col_pol EXCEPT hr_batch;

Why: the record is written only when the statement actually references one of the listed columns. SELECT employee_id, last_name FROM hr.employees generates nothing; SELECT salary ... does. This replaces most uses of the desupported fine-grained auditing (DBMS_FGA) and cuts audit volume dramatically on wide tables. Works for tables and views.

Test:

SQL

CONNECT app_user/"App#2026"@pdb1

SELECT last_name FROM hr.employees WHERE employee_id = 100; -- not audited

SELECT salary FROM hr.employees WHERE employee_id = 100; -- audited

Step 5 — Privilege and role auditing

SQL

CREATE AUDIT POLICY priv_use_pol

PRIVILEGES SELECT ANY TABLE, ALTER ANY TABLE, EXEMPT ACCESS POLICY, EXEMPT REDACTION POLICY;

AUDIT POLICY priv_use_pol;

CREATE AUDIT POLICY dba_role_pol

ROLES dba;

AUDIT POLICY dba_role_pol;

-- account and parameter changes: use the predefined policies

AUDIT POLICY ora_account_mgmt;

AUDIT POLICY ora_database_parameter;

Why: privilege auditing records every statement that used the privilege (e.g. a SELECT on a table the user has no direct grant for). ROLES dba audits everything the role makes possible — cheap coverage of privileged accounts. The bypass privileges for VPD and Data Redaction belong in every privilege policy.

Step 6 — Top-level statements only (reduce recursion noise)

SQL

CREATE AUDIT POLICY hr_toplevel_pol

ACTIONS ALL ON hr.employees

ONLY TOPLEVEL;

AUDIT POLICY hr_toplevel_pol BY app_user;

Why: without ONLY TOPLEVEL, a procedure that touches HR.EMPLOYEES ten times produces ten records per call. With it, only the statement the user issued is recorded.

Step 7 — Enrich records with application context

SQL

AUDIT CONTEXT NAMESPACE sales_ctx ATTRIBUTES region, app_module BY app_user;

-- and for connection pools, always set the client identifier in the application:

-- DBMS_SESSION.SET_IDENTIFIER('jsmith');

Why: with connection pools every session is APP_USER; the CLIENT_IDENTIFIER and application-context values (APPLICATION_CONTEXTS column) are what tell you which human was behind the statement.

Step 8 — Read the trail

SQL

SELECT event_timestamp, dbusername, client_identifier, action_name,

object_schema, object_name, sql_text, unified_audit_policies, return_code

FROM unified_audit_trail

WHERE unified_audit_policies LIKE '%HR_SALARY_COL_POL%'

AND event_timestamp > SYSTIMESTAMP - INTERVAL '1' DAY

ORDER BY event_timestamp DESC;

-- failed logons in the last 24 h (ORA_LOGON_FAILURES)

SELECT event_timestamp, dbusername, userhost, return_code

FROM unified_audit_trail

WHERE action_name = 'LOGON' AND return_code <> 0 AND event_timestamp > SYSTIMESTAMP - 1;

Why: filter on EVENT_TIMESTAMP first — the view sits on a partitioned table and time-based filters prune partitions. RETURN_CODE = 0 means success.

Step 9 — Move the audit trail to its own tablespace and partition it

SQL

CREATE TABLESPACE audit_ts DATAFILE SIZE 2G AUTOEXTEND ON;

BEGIN

DBMS_AUDIT_MGMT.SET_AUDIT_TRAIL_LOCATION(

audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_UNIFIED,

audit_trail_location_value => 'AUDIT_TS');

DBMS_AUDIT_MGMT.ALTER_PARTITION_INTERVAL(

interval_number => 1,

interval_frequency => 'DAY');

END;

/

Why: keeps SYSAUX from filling up and makes purges (partition drops) fast. Daily partitions suit busy systems; monthly is the default.

Step 10 — Archive and purge

SQL

BEGIN

-- tell the database what has already been archived (e.g. shipped to SIEM)

DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP(

audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_UNIFIED,

last_archive_time => SYSTIMESTAMP - INTERVAL '90' DAY);

-- recurring purge of everything older than the archive timestamp

DBMS_AUDIT_MGMT.CREATE_PURGE_JOB(

audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_UNIFIED,

audit_trail_purge_interval => 24, -- hours

audit_trail_purge_name => 'UNIFIED_PURGE_JOB',

use_last_arch_timestamp => TRUE);

END;

/

-- one-off manual purge

EXEC DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL(audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_UNIFIED, use_last_arch_timestamp => TRUE);

Why: retention is a compliance decision (often 1 year online, 7 years archived). The purge job must run — an unpurged trail eventually fills the tablespace and, in the worst case, stops the database from writing audit records.

Step 11 — Send records to the OS log / SIEM

SQL

ALTER SYSTEM SET UNIFIED_AUDIT_SYSTEMLOG = 'local0.info' SCOPE = SPFILE; -- Linux syslog facility.priority

Why: a summary of every audit record goes to syslog in near real time — a copy the DBA cannot delete. Full records stay in the database. On OCI, Data Safe collects the trail; on-premises, ship the syslog stream to your SIEM.

Step 12 — Maintain policies

SQL

NOAUDIT POLICY hr_toplevel_pol BY app_user;

ALTER AUDIT POLICY hr_emp_dml_pol ADD ACTIONS LOCK ON hr.employees, FLASHBACK ON hr.employees;

ALTER AUDIT POLICY priv_use_pol ADD PRIVILEGES CREATE ANY PROCEDURE;

DROP AUDIT POLICY hr_toplevel_pol;

-- all audit configuration changes are themselves audited

SELECT event_timestamp, dbusername, action_name, sql_text

FROM unified_audit_trail WHERE action_name LIKE '%AUDIT POLICY%' ORDER BY 1 DESC;

Why: ALTER AUDIT POLICY ... ADD/DROP lets you evolve policies without dropping and recreating them (a change takes effect for new sessions). The list of auditable actions per object type is in AUDITABLE_SYSTEM_ACTIONS and the SQL Language Reference. Policy changes cannot be hidden; they are always recorded, even for SYS.

Sizing and performance notes

  • Audit writes are asynchronous-friendly inserts into a partitioned table; the cost is dominated by how much you audit. Column-level policies, ONLY TOPLEVEL and WHEN conditions are your tuning knobs.

  • SELECT auditing on hot tables is the most expensive choice — combine with a WHEN clause or restrict BY user.

  • Watch DBA_AUDIT_MGMT_CONFIG_PARAMS and the size of AUDSYS.AUD$UNIFIED weekly.

Recommended minimum policy set

Policy

Purpose

ORA_SECURECONFIG, ORA_LOGON_FAILURES (predefined)

Security-relevant DDL and failed logons

ORA_ACCOUNT_MGMT, ORA_DATABASE_PARAMETER (predefined)

User/role changes, parameter changes

Privilege policy on * ANY *, EXEMPT ACCESS POLICY, EXEMPT REDACTION POLICY

Use of powerful privileges

ROLES dba

Everything done through the DBA role

Column-level policies on PII / financial columns

Targeted access evidence

SQL Firewall component policy (if enabled)

Violations in the tamper-evident trail


Recent Posts

See All

Comments


bottom of page