How To Delete Record From dba_audit_trail in Oracle 11gR2
-
28-02-2021 - |
Вопрос
I want to delete records older than one month from AUD$ table, but I have to do this on dba_audit_trail, because I have to do this job according dba_audit_trail's timestamp. I can't find any clear solution for it.
CREATE OR REPLACE PROCEDURE CU
AS
BEGIN
execute immediate 'delete from SYS.AUD$ where TIMESTAMP > SYSDATE - 30;
END;
/
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'CLEANUP_AUDIT',
job_type => 'STORED_PROCEDURE',
job_action => 'BEGIN CU(); END;',
start_date => 'I will set it after.',
repeat_interval => 'I will set it after.',
enabled => 'TRUE',
comments => 'I will set it after.');
END;
/
Or can I delete on dba_audit_trail directly?
Regards,
Решение
First execute INIT_CLEANUP
, that you need to use only once.
Next execute CREATE_PURGE_JOB
with use_last_arch_timestamp => true
, which creates the scheduled job for cleaning the audit trail, also need to use only once.
Finally you need to take care of advancing the last archive timestamp with SET_LAST_ARCHIVE_TIMESTAMP
, which you can simply schedule and set it to sysdate-30
, or call it as part of your archiving process and set it to the timestamp of last archival, if you use any.
It is also a good idea to create a dedicated tablespace to your audit trail and place it there with SET_AUDIT_TRAIL_LOCATION
.