SYSAUX表空间清理相关脚本
金蝶云社区-风清
风清
0人赞赏了该文章 1,154次浏览 未经作者许可,禁止转载编辑于2017年06月26日 14:34:24

truncate table sys.WRI$_OPTSTAT_HISTHEAD_HISTORY;
truncate table sys.WRI$_OPTSTAT_HISTGRM_HISTORY;

exec dbms_stats.purge_stats(sysdate-101);
exec dbms_stats.purge_stats(sysdate-51);
exec dbms_stats.purge_stats(sysdate-5);
exec dbms_stats.alter_stats_history_retention(10);
alter table sys.WRI$_OPTSTAT_HISTHEAD_HISTORY move tablespace sysaux;
alter index sys.I_WRI$_OPTSTAT_HH_OBJ_ICOL_ST rebuild online;
alter index sys.I_WRI$_OPTSTAT_HH_ST rebuild online;
alter table sys.WRI$_OPTSTAT_HISTGRM_HISTORY move tablespace sysaux;
alter index sys.I_WRI$_OPTSTAT_H_OBJ#_ICOL#_ST rebuild online;
alter index sys.I_WRI$_OPTSTAT_H_ST rebuild online;
alter table sys.WRI$_OPTSTAT_IND_HISTORY move tablespace sysaux;
alter index sys.I_WRI$_OPTSTAT_IND_OBJ#_ST rebuild online;
alter index sys.I_WRI$_OPTSTAT_IND_ST rebuild online;
alter table sys.WRI$_OPTSTAT_TAB_HISTORY move tablespace sysaux;
alter index sys.I_WRI$_OPTSTAT_TAB_OBJ#_ST rebuild online;
alter index sys.I_WRI$_OPTSTAT_TAB_ST rebuild online;
ALTER TABLE SYS.WRI$_OPTSTAT_OPR MOVE TABLESPACE SYSAUX;
ALTER TABLE SYS.WRI$_OPTSTAT_AUX_HISTORY MOVE TABLESPACE SYSAUX;
ALTER INDEX SYS.I_WRI$_OPTSTAT_AUX_ST REBUILD ONLINE;
ALTER INDEX SYS.I_WRI$_OPTSTAT_OPR_STIME REBUILD ONLINE;
EXEC dbms_stats.gather_table_stats(ownname => 'SYS',tabname => 'WRI$_OPTSTAT_HISTHEAD_HISTORY',cascade => TRUE);
EXEC dbms_stats.gather_table_stats(ownname => 'SYS',tabname => 'WRI$_OPTSTAT_HISTGRM_HISTORY',cascade => TRUE);
EXEC dbms_stats.gather_table_stats(ownname => 'SYS',tabname => 'WRI$_OPTSTAT_IND_HISTORY',cascade => TRUE);
EXEC dbms_stats.gather_table_stats(ownname => 'SYS',tabname =>'WRI$_OPTSTAT_TAB_HISTORY',cascade => TRUE);
EXEC dbms_stats.gather_table_stats(ownname => 'SYS',tabname => 'WRI$_OPTSTAT_OPR',cascade => TRUE);
EXEC dbms_stats.gather_table_stats(ownname => 'SYS',tabname => 'WRI$_OPTSTAT_AUX_HISTORY',cascade => TRUE);

delete from sys.wrh$_active_session_history a where not exists (select 1 from sys.wrm$_snapshot b where a.snap_id=b.snap_id and a.dbid=b.dbid and a.instance_number=b.instance_number);

alter table sys.wrh$_active_session_history enable row movement;
alter table sys.wrh$_active_session_history shrink space cascade;
alter table sys.wrh$_active_session_history disable row movement;
EXEC dbms_stats.gather_table_stats(ownname => 'SYS',tabname => 'WRH$_ACTIVE_SESSION_HISTORY',cascade => TRUE);