昨天,在11g數據庫上發現了sys.aud$表增大到8G左右,清除方法如下:
第一步
EXEC DBMS_AUDIT_MGMT.INIT_CLEANUP(DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD, 12);
第二步
EXEC DBMS_AUDIT_MGMT.CLEAN_AUDIT_TRAIL(DBMS_AUDIT_MGMT.AUDIT_TRAIL_AUD_STD, FALSE);
不執行第一步會報ORA-46258錯誤。
但問題是,在第一次執行第一步的時候,系統會把AUD$表從SYSTEM 表空間move到SYSAUX表空間。
聯機文檔裏的說明如下:
INIT_CLEANUP Procedure
This procedure sets up the audit management infrastructure and a default cleanup interval for the audit trail records. If the audit trail tables are in the SYSTEM
tablespace, then the procedure moves them to the SYSAUX
tablespace.
ORA-46267: Insufficient space in 'SYSAUX' tablespace, cannot complete operation
於是又找了metalink notes How to Truncate, Delete, or Purge Rows from the Audit Trail Table AUD$ [ID 73408.1],可以對此表進行truncate。
但由於是正式庫,怕truncate操作會帶來其他的一些問題,不直接做truncate,而是執行以下命令:
truncate table sys.aud$ reuse storage;
alter table sys.aud$ deallocate unused keep 8640m;
alter table sys.aud$ deallocate unused keep 7000m;
alter table sys.aud$ deallocate unused keep 6000m;
...
alter table sys.aud$ deallocate unused keep 10m;
truncate過程1-2分鐘之內結束,最後sys.aud$變成10M。
如果想刪除大表也可以這麼操作(delete操作耗資源),只是不一定那麼快釋放空間,這還要看具體情況了。