SYSAUX表空间一直增长,一个月增长快10G,需要定时维护表空间
原因oracle bug引起 (Doc ID 1055547.1)
MMON performs the purge of the optimizer stats history automatically. However it has an internal limit of 5 minutes to perform this job. If the operation takes more than 5 minutes, then it is aborted and stats not purged.
No trace or alert message is reported.
因为进行统计信息收集时需要往下面相关表插入数据,清理期间不能进行统计数据收集。
wri$_optstat_tab_history
wri$_optstat_ind_history
wri$_optstat_histhead_history
wri$_optstat_histgrm_history
登录ebs将两个(一个GL、一个ALL)计划请求 统计数据模式 给取消掉(取消前截屏备份参数)。
删除历史数据下面所有sql均以 sys as dba 执行
先算出现有数据总最早日期是多少天前的。
SELECT TRUNC(SYSDATE) - TO_DATE(to_char(MIN(savtime), 'YYYY-MM-DD'), 'yyyy-mm-dd')
FROM sys.WRI$_OPTSTAT_HISTHEAD_HISTORY;
假设是190天,则通过远程桌面登录sqlplus (下面这个sql可能耗时好几天,需要后台运行或者远程桌面运行)
set serveroutput on
BEGIN
DBMS_OUTPUT.ENABLE(buffer_size => null);
for i in reverse 10..190
loop
dbms_output.put_line(to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') || '-Begin delete Day ' || i );
dbms_stats.purge_stats(sysdate-i);
COMMIT;
dbms_output.put_line(to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') || '-Complete delete Day ' || i );
end loop;
end;
/
上面这个sql可能执行数天,执行完成后利用shink进行表收缩。
进行表收缩--先备份索引数据
select dbms_metadata.get_ddl('INDEX','I_WRI$_OPTSTAT_HH_OBJ_ICOL_ST','SYS') from dual;
select dbms_metadata.get_ddl('INDEX','I_WRI$_OPTSTAT_HH_ST','SYS') from dual;
-- Drop indexes
drop index I_WRI$_OPTSTAT_HH_OBJ_ICOL_ST;
drop index I_WRI$_OPTSTAT_HH_ST;
--开启行迁移
alter table WRI$_OPTSTAT_HISTHEAD_HISTORY enable row movement;
--进行收缩(此处没有用move是为了节省空间)
alter table WRI$_OPTSTAT_HISTHEAD_HISTORY shrink space cascade;
--收缩完毕后进行索引重建
CREATE UNIQUE INDEX "SYS"."I_WRI$_OPTSTAT_HH_OBJ_ICOL_ST" ON "SYS"."WRI$_OPTSTAT_HISTHEAD_HISTORY" ("OBJ#", "INTCOL#", SYS_EXTRACT_UTC("SAVTIME"), "COLNAME")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ;
CREATE INDEX "SYS"."I_WRI$_OPTSTAT_HH_ST" ON "SYS"."WRI$_OPTSTAT_HISTHEAD_HISTORY" (SYS_EXTRACT_UTC("SAVTIME"))
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1
BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "SYSAUX" ;
收集统计信息
EXEC dbms_stats.gather_table_stats(ownname => ‘SYS’,tabname => ‘WRI$_OPTSTAT_HISTHEAD_HISTORY’,cascade => TRUE);
查看效果
SELECT *
FROM (SELECT owner, segment_name, segment_type, SUM(bytes) / 1024 / 1024 / 1024 GB
FROM dba_segments
WHERE tablespace_name = 'SYSAUX'
GROUP BY owner, segment_name, segment_type
ORDER BY 4 DESC)
WHERE rownum < 10;
SELECT occupant_name "Item",
space_usage_kbytes / 1048576 "Space Used (GB)",
schema_name "Schema",
move_procedure "Move Procedure"
FROM v$sysaux_occupants
ORDER BY space_usage_kbytes DESC;
恢复统计模式信息收集
立刻提交一次ALL模式的统计,然后再设定一个计划请求,ALL模式,每周五晚上10点进行数据收集,参数参考备份截屏。
因为总账模式每周数据规模变化不大,为了省电,不必再设定计划请求每天晚上运行。
非EBS库需要用对应的api来启用停用统计信息收集。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)