Oracle 審計表AUD$遷移表空間及創建清理job
1、查看audit是否已經打開
SQL> show parameter audit_trail
NAME TYPE VALUE
audit_trail string DB, EXTENDED
2、創建audit tablespace
create tablespace ts_audit datafile ‘/oradata/ora10g/audit01.dbf‘ size 4000M autoextend off;
3、設置清理頻率
BEGIN
DBMS_AUDIT_MGMT.INIT_CLEANUP(
default_cleanup_interval => 12 / hours /);
END;
/
4、將AUD$從SYSTEM表空間遷移到新的表空間
BEGIN
DBMS_AUDIT_MGMT.SET_AUDIT_TRAIL_LOCATION(
audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,
audit_trail_location_value => ‘TS_AUDIT‘);
END;
/
5、設置last archive timestamp,保留30天
DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP(
audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,
last_archive_time => SYSDATE-30);
END;
/
6、設置last archive timestamp job,保留30天
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => SET_AUDIT_ARCHIVE_TIMESTAMP‘,
job_type => ‘PLSQL_BLOCK‘,
job_action => ‘BEGIN DBMS_AUDIT_MGMT.SET_LAST_ARCHIVE_TIMESTAMP(AUDIT_TRAIL_TYPE => DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,LAST_ARCHIVE_TIME => SYSDATE-30); END;‘,
repeat_interval => ‘FREQ=HOURLY;INTERVAL=24‘,
enabled => TRUE,
comments => ‘set last archive timestamp‘
);
END;
/
7、定義自動清理job
BEGIN
DBMS_AUDIT_MGMT.CREATE_PURGE_JOB(
audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,
audit_trail_purge_interval => 24 / hours /,
audit_trail_purge_name => ‘AUDIT_CLEANUP_JOB‘,
use_last_arch_timestamp => TRUE);
END;
/
8、查看清理job執行情況,delete_count應該不為0
SQL> select * from dba_audit_mgmt_clean_events;
AUDIT_TRAIL RAC_INSTANCE CLEANUP_TIME DELETE_COUNT WAS
STANDARD AUDIT TRAIL 0 16-MAY-19 07.18.59.937786 AM +00:00 460 NO
Oracle 審計表AUD$遷移表空間及創建清理job