從truncate sys.aud$想到的刪除大表的方法

昨天,在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表空間。
ide

聯機文檔裏的說明以下:
spa

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.code

 

若是SYSAUX的空間不夠,又沒有設置autoextend on,就會報錯ORA-4626。

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。ci

但因爲是正式庫,怕truncate操做會帶來其餘的一些問題,不直接作truncate,而是執行如下命令:
資源

truncate table sys.aud$ reuse storage;
文檔

alter table sys.aud$ deallocate unused keep 8640m;
it

 

alter table sys.aud$ deallocate unused keep 7000m;
io

alter table sys.aud$ deallocate unused keep 6000m;table

...

alter table sys.aud$ deallocate unused keep 10m;

truncate過程1-2分鐘以內結束,最後sys.aud$變成10M。

若是想刪除大表也能夠這麼操做(delete操做耗資源),只是不必定那麼快釋放空間,這還要看具體狀況了。

相關文章
相關標籤/搜索