從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表空間。

聯機文檔裏的說明如下:

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.

 

如果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。

但由於是正式庫,怕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操作耗資源),只是不一定那麼快釋放空間,這還要看具體情況了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章