Oracle审计表AUD$迁移表空间及创建清理job

Oracle 10.2.0.5以上的版本可以使用DBMS_AUDIT_MGMT清理audit
1、查看audit是否已经打开
SQL> show parameter audit_trail

创新互联公司-专业网站定制、快速模板网站建设、高性价比如东网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式如东网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖如东地区。费用合理售后完善,10年实体公司更值得信赖。

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(
audit_trail_type => DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD,
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天
BEGIN
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;',
start_date => sysdate,
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
网页路径:http://scyanting.com/article/iiopho.html