oracle数据管理

[转] Autotrace with bind variables

September 27, 2013 Internals, oracle No comments

JL刚刚写的一篇autotrace与bind variables 的行为:Autotrace trick
之前我们也发现过这个问题具体SR在这里:something seems confused

SYSAUX 表空间问题解决

October 19, 2011 maintain, oracle No comments

通过awrinfo.sql 以及 v$sysaux_occupants对SYSAUX空间分析,发现OPTSTAT(历史统计信息)相关的表占用近28G,AWR相关占用空间4G多,经分析OPTSTAT的历史
统计信息系统会自动清理失败有如下原因:因为历史统计信息较多,通过DBMS_STATS.PURGE_STATS清理比较困难,因此与客户沟通后对wri$_optstat_histhead_history
和wri$_optstat_histgrm_history进行TRUNCATE后再通过DBMS_STATS.PURGE_STATS清理其它表的数据,并清理一些无效的ASH数据

一.清理SYSAUX下的历史统计信息
1.将历史统计信息保留时间设为无限
exec dbms_stats.alter_stats_history_retention(-1);
2.truncate较大的TABLE
truncate table sys.WRI$_OPTSTAT_HISTHEAD_HISTORY;
truncate table sys.WRI$_OPTSTAT_HISTGRM_HISTORY;
3.清理历史统计信息
exec dbms_stats.purge_stats(sysdate-101);
exec dbms_stats.purge_stats(sysdate-51);
exec dbms_stats.purge_stats(sysdate-5);
4.将历史统计信息保留时间设为10天
exec dbms_stats.alter_stats_history_retention(10);
5.将历史统计信息相关的表进行MOVE
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;
6.对MOVE表的统计信息进行收集
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);

二.清理SYAUX下的无效ASH信息

1.检查是否有无效的ASH信息
select count(*)
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);
2.清理无效的ASH信息
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);
3.对ASH表清理后的碎片整理
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;
4.收集碎片整理后表的统计信息
EXEC dbms_stats.gather_table_stats(ownname => ‘SYS’,tabname => ‘WRH$_ACTIVE_SESSION_HISTORY’,cascade => TRUE);
3.检查表空间可收缩的的位置
select a.FILE#,
a.NAME,
a.BYTES / 1024 / 1024 mb,
ceil(HWM * A.BLOCK_SIZE) / 1024 / 1024 RESIZETO,
‘ALTER DATABASE DATAFILE ”’ || A.NAME || ”’ RESIZE ‘ ||
(trunc(CEIL(HWM * A.BLOCK_SIZE) / 1024 / 1024)+20) || ‘M;’ RESIZECMD
from v$datafile a,
(SELECT C.file_id, MAX(C.block_id + C.blocks – 1) HWM
FROM DBA_EXTENTS C
GROUP BY FILE_ID) B
WHERE A.FILE# = B.FILE_ID
AND a.tablespace=’SYSAUX’
ORDER BY 5;

三.SYSAUX清理后的检查

1.清理后的无效INDEX检查
select * from dba_indexes where status<>‘VALID’ AND STATUS<>‘N/A’;
SELECT * FROM DBA_IND_PARTITIONS WHERE STATUS<>‘USABLE’ AND STATUS<>‘N/A’;
SELECT * FROM DBA_IND_SUBPARTITIONS WHERE STATUS<>‘USABLE’;
上面语句应均无数据返回,如有则对这些INDEX进行重建
2.清理后的INDEX并行度检查
select * from dba_indexes where degree not in (‘1′,’0′,’DEFAULT’);

reference:METALINK doc 287679.1