Skip to content

Commit

Permalink
ua-audit-log-cleanup-job.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
jkstill committed Apr 26, 2024
1 parent a80be2c commit cc8172d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions INDEX
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ Unified Auditing

@options.sql: report from v$option - check for 'Unified Auditing'
@ua-actions.sql: All possible Unified Auditing Actions
@ua-audit-log-cleanup-job.sql: simple example of creating a scheduler job to purge the unified audit trail
@ua-policies.sql: A report of UA policies
@ua-sessions.sql: Report on LOGON and LOGOFF auditing

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,7 @@
<pre>
<a href='https://github.com/jkstill/oracle-script-lib/blob/master/sql/options.sql'>options.sql</a> - report from v$option - check for 'Unified Auditing'
<a href='https://github.com/jkstill/oracle-script-lib/blob/master/sql/ua-actions.sql'>ua-actions.sql</a> - All possible Unified Auditing Actions
<a href='https://github.com/jkstill/oracle-script-lib/blob/master/sql/ua-audit-log-cleanup-job.sql'>ua-audit-log-cleanup-job.sql</a> - simple example of creating a scheduler job to purge the unified audit trail
<a href='https://github.com/jkstill/oracle-script-lib/blob/master/sql/ua-policies.sql'>ua-policies.sql</a> - A report of UA policies
<a href='https://github.com/jkstill/oracle-script-lib/blob/master/sql/ua-sessions.sql'>ua-sessions.sql</a> - Report on LOGON and LOGOFF auditing
</pre>
Expand Down
36 changes: 36 additions & 0 deletions sql/ua-audit-log-cleanup-job.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

-- ua-audit-log-cleanup-job.sql
-- Retention is 30 days

create or replace procedure ua_log_purge (retention_days integer)
is

begin

dbms_audit_mgmt.set_last_archive_timestamp (
audit_trail_type => dbms_audit_mgmt.audit_trail_unified,
last_archive_time => systimestamp - retention_days
);

dbms_audit_mgmt.clean_audit_trail(
audit_trail_type => dbms_audit_mgmt.audit_trail_unified,
use_last_arch_timestamp => true
);

end;
/


begin
dbms_scheduler.create_job (
job_name => 'UA_LOG_PURGE_JOB',
job_type => 'PLSQL_BLOCK',
job_action => 'begin sys.ua_log_purge(30); end;',
start_date => systimestamp + interval '1' Hour,
repeat_interval => 'FREQ=DAILY',
enabled => true
);
end;
/


0 comments on commit cc8172d

Please sign in to comment.