查看: 1049|回复: 0

[Oracle数据库] oracle 11G AWR不自动清理

发表于 2018-4-3 08:00:08

理论上AWR数据应当根据保留时间,自动清理,但是实际上,经常碰到这样的:

  1. col segment_name for a32;
  2. set linesize 500;
  3. set pagesize 500;
  4. with t1 as (
  5. select round(sum(bytes)/1024/1024) MB,segment_name from dba_segments where owner='SYS'
  6. group by segment_name
  7. order by 1 desc )
  8. select * from t1 where rownum<16;
复制代码

然后WRH$开头的几个表占十几个G的情况,也就是AWR数据并没有完全被清理掉,检查策略一切正常:

  1. SQL> select INSTANCE_NUMBER, min(SAMPLE_TIME), max(SAMPLE_TIME) from
  2. WRH$_ACTIVE_SESSION_HISTORY group by INSTANCE_NUMBER; 2
  3. INSTANCE_NUMBER MIN(SAMPLE_TIME) MAX(SAMPLE_TIME)
  4. --------------- ------------------------- --------------------------------------------------
  5. 1 25-MAY-16 08.14.48.613 PM 28-MAR-18 08.56.02.944 AM
  6. SQL> select snap_interval,retention from dba_hist_wr_control;
  7. SNAP_INTERVAL RETENTION
  8. ------------------------------------ ---------------------------------------------------------------------------
  9. +00000 01:00:00.0 +00008 00:00:00.0
  10. SQL> select min(snap_id),max(snap_id) from WRH$_EVENT_HISTOGRAM;
  11. MIN(SNAP_ID) MAX(SNAP_ID)
  12. ------------ ------------
  13. 1 16015
复制代码

MOS查一下BUG号14084247,从 11.2.0.3之后几乎都有这个问题,并且打了14084247 之后,貌似也不能解决,MOS又发一篇文章,手动清理,DOCID387914.1,步骤如下:
1检查分区情况

  1. SELECT owner,
  2. segment_name,
  3. partition_name,
  4. segment_type,
  5. bytes/1024/1024/1024 Size_GB
  6. FROM dba_segments
  7. WHERE segment_name='WRH$_ACTIVE_SESSION_HISTORY';
复制代码

2 修改隐含参数:
alter session set "_swrf_test_action" = 72;
3 再次检查分区情况
4 统计各个WRH表的最大,最小snap_id

  1. set serveroutput on
  2. declare
  3. CURSOR cur_part IS
  4. SELECT partition_name from dba_tab_partitions
  5. WHERE table_name = 'WRH$_ACTIVE_SESSION_HISTORY';
  6. query1 varchar2(200);
  7. query2 varchar2(200);
  8. TYPE partrec IS RECORD (snapid number, dbid number);
  9. TYPE partlist IS TABLE OF partrec;
  10. Outlist partlist;
  11. begin
  12. dbms_output.put_line('PARTITION NAME SNAP_ID DBID');
  13. dbms_output.put_line('--------------------------- ------- ----------');
  14. for part in cur_part loop
  15. query1 := 'select min(snap_id), dbid from sys.WRH$_ACTIVE_SESSION_HISTORY partition ('||part.partition_name||') group by dbid';
  16. execute immediate query1 bulk collect into OutList;
  17. if OutList.count > 0 then
  18. for i in OutList.first..OutList.last loop
  19. dbms_output.put_line(part.partition_name||' Min '||OutList(i).snapid||' '||OutList(i).dbid);
  20. end loop;
  21. end if;
  22. query2 := 'select max(snap_id), dbid from sys.WRH$_ACTIVE_SESSION_HISTORY partition ('||part.partition_name||') group by dbid';
  23. execute immediate query2 bulk collect into OutList;
  24. if OutList.count > 0 then
  25. for i in OutList.first..OutList.last loop
  26. dbms_output.put_line(part.partition_name||' Max '||OutList(i).snapid||' '||OutList(i).dbid);
  27. dbms_output.put_line('---');
  28. end loop;
  29. end if;
  30. end loop;
  31. end;
  32. /
复制代码

5 删除不需要的数据

DBMS_WORKLOAD_REPOSITORY.DROP_SNAPSHOT_RANGE(
low_snap_id IN NUMBER,
high_snap_id IN NUMBER
dbid IN NUMBER DEFAULT NULL);

6 运行 @?/rdbms/admin/awrinfo.sql再次检查下
7 最后建议重启一下MMON刷新:

  1. alter system set "_swrf_mmon_flush"=false;
  2. alter system set "_swrf_mmon_flush"=true;
复制代码


回复

使用道具 举报