Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3552388
  • 博文数量: 715
  • 博客积分: 1860
  • 博客等级: 上尉
  • 技术积分: 7745
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-07 08:51
个人简介

偶尔有空上来看看

文章分类

全部博文(715)

文章存档

2023年(75)

2022年(134)

2021年(238)

2020年(115)

2019年(11)

2018年(9)

2017年(9)

2016年(17)

2015年(7)

2014年(4)

2013年(1)

2012年(11)

2011年(27)

2010年(35)

2009年(11)

2008年(11)

最近访客

分类: Oracle

2023-01-08 15:32:44

从11.2.0.1开始,可以通过视图看告警日志内容(老版本的怎么办?看文末)
原理是通过外部表来关联到具体的告警日志文件(你猜是关联xml格式还是.log文件?)

当然有可能出现的问题就是引起高cpu或看不到最新的告警日志
高CPU是因为日志文件太大了 ,解决方法见 [DOC ID 2056666.1]
看不到最新内容可能是文件被损坏了,见 [DOC ID 2262659.1]

从11g开始,oracle提供了 x$dbgalertext 视图,关联xml格式的告警信息

  1. set lin 200 pages 1000
  2. col message_text for a80
  3. col riqi for a22

  4. select to_char(originating_timestamp,'yyyy-mm-dd hh24:mi:ss')riqi,message_text
  5. from x$dbgalertext
  6. where originating_timestamp > sysdate - 7 and
  7.   (message_text = 'ORA-00600'
  8. OR message_text LIKE '%fatal%'
  9. OR message_text LIKE '%error%'
  10. OR message_text LIKE '%ORA-%'
  11. OR message_text LIKE '%terminating the instance%'
  12. );
message_text这么多like 是推荐的,看着MESSAGE_TYPE message_leve 很香,但不是你认为的香。

还是老实的like吧,不信的话

  1. col message_text for a80
  2. select message_level,count(0) from x$dbgalertext group by message_level;

  3. col COMPONENT_ID for a20
  4. select COMPONENT_ID,count(0) from x$dbgalertext group by COMPONENT_ID;

  5. col riqi for a12
  6. select to_char(originating_timestamp,'yyyy-mm-dd') riqi,count(0) from x$dbgalertext group by to_char(originating_timestamp,'yyyy-mm-dd') order by 1;

看看效果就知道了

从oracle 12.2开始可以把视图替换为 v$diag_alert_ext 

  1. set lin 200 pages 1000
  2. col message_text for a80
  3. col riqi for a22
  4. select to_char(originating_timestamp,'yyyy-mm-dd hh24:mi:ss')riqi,message_text
  5. from v$diag_alert_ext
  6. where originating_timestamp > sysdate - 7 and
  7.   (
  8. message_text = 'ORA-00600'
  9. OR message_text LIKE '%fatal%'
  10. OR message_text LIKE '%error%'
  11. OR message_text LIKE '%ORA-%'
  12. OR message_text LIKE '%terminating the instance%'
  13. );
  14.   

  15. 或者看最近一小时的(如果嫌慢的话)

  16. col msg for a120
  17. with oneday as (select /*+ materialize */ * from
  18.  v$diag_alert_ext where ORIGINATING_TIMESTAMP>systimestamp-1)
  19. select to_char(ORIGINATING_TIMESTAMP,'YYYY-MM-DD HH24:MI:SS')||' ' || message_text msg from oneday
  20. where ORIGINATING_TIMESTAMP>systimestamp-5*(1/24/60) and -- 最近5分钟
  21. message_text like '%ORA-%' and
  22. message_text not like '%result of ORA-609%' and
  23. message_text not like '%result of ORA-28%' and
  24. message_text not like '%(ORA-3136)%' and
  25. message_text not like '%ORA-01013:%';

  26.     
  27. col message_text for a80
  28. select message_level,count(0) from v$diag_alert_ext group by message_level;

  29. col COMPONENT_ID for a20
  30. select COMPONENT_ID,count(0) from v$diag_alert_ext group by COMPONENT_ID;

  31. col riqi for a12
  32. select to_char(originating_timestamp,'yyyy-mm-dd') riqi,count(0) from v$diag_alert_ext group by to_char(originating_timestamp,'yyyy-mm-dd') order by 1;
效果如下:


11g以前的呢?
  1. create directory BDUMP as '/u01/app/oracle/admin/orcl/bdump';

  2. create table
  3.    alert_log ( msg varchar2(200) )
  4. organization external (
  5.    type oracle_loader
  6.    default directory BDUMP
  7.    access parameters (
  8.       records delimited by newline
  9.    )
  10.    location('alert_test.log')
  11. )
  12. reject limit 1000;

  13. select msg from alert_log where msg like 'ORA-%';
凑合用吧。
但是普通用户无法访问X$DBGALERTEXT, 需要定制一下
create or replace view SYS.MGMT_ALERT_LOG as select * from X$DBGALERTEXT;
grant select on MGMT_ALERT_LOG to DB_MONITOR;

阅读(641) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~