在Oracle中,Oracle 10g和11g告警日誌文件的位置在哪裏?程序員
做爲一名DBA,必須知道告警日誌是什麼,在何處。實時的監控數據庫的告警日誌是必須進行的工做。監控而且根據不一樣的告警級別,經過郵件或短信發送告警信息給DBA,這能夠幫助DBA及時瞭解數據庫的變化與異常,及時響應並介入處理。面試
告警日誌文件有2種類型,一種是純文本格式的,另一種是xml文件格式的,平時查看最多地是純文本格式的告警日誌。告警日誌的內容包含:消息和錯誤的類型、ORA-600內部錯誤、ORA-1578塊損壞錯誤、ORA-12012做業隊列錯誤、實例啓動關閉,恢復等信息、特定的DDL命令、影響表空間,數據文件及回滾段的命令、可持續的命令被掛起、LGWR不能寫入到日誌文件、歸檔進程啓動信息、調度進程的相關信息和動態參數的修改信息等。sql
不管是Oracle 10g仍是11g,其告警日誌的位置均可以由參數BACKGROUND_DUMP_DEST來查詢,只不過在Oracle 11g中位置有所變化。在Oracle 10g中,告警日誌通常在$ORACLE_BASE/admin/$ORACLE_SID/bdump目錄下:數據庫
1SYS@lhrdb> SHOW PARAMETER BACKGROUND_DUMP_DEST
2NAME TYPE VALUE
3------------------------------------ ----------- ------------------------------
4background_dump_dest string /u01/app/oracle/admin/lhrdb/bdump
:
1SYS@lhrdb> SHOW PARAMETER BACKGROUND_DUMP_DEST
2
3NAME TYPE VALUE
4------------------------------------ ---------------------- ------------------------------
5background_dump_dest string /oracle/app/oracle/diag/rdbms/lhrdb/lhrdb/trace
6[ZFZHLHRDB1:oracle]:/oracle>cd /oracle/app/oracle/diag/rdbms/lhrdb/lhrdb/trace
7[ZFZHLHRDB1:oracle]:/oracle/app/oracle/diag/rdbms/lhrdb/lhrdb/trace>ls -l alert*
8-rw-r----- 1 oracle asmadmin 13852942 Oct 17 13:22 alert_lhrdb.log
:
1SQL> SELECT d.VALUE FROM V$DIAG_INFO d WHERE d.NAME='Diag Trace';
2VALUE
3---------------------------------------------------------
4/u01/app/oracle/diag/rdbms/lhrdb/lhrdb/trace
1drop directory DIR_ALERT;
2create directory DIR_ALERT as '/u01/app/oracle/diag/rdbms/orclasm/orclasm/trace';
3
4drop table alert_log;
5create table alert_log(
6 text varchar2(500)
7 )organization external
8 (type oracle_loader
9 default directory DIR_ALERT
10 access parameters
11 (records delimited by newline
12 )location('alert_orclasm.log')
13 ) reject limit unlimited;
14
15select * from alert_log where text like 'ORA-%';
1select * from (
2select rownum rn,a.text from alert_log a) b where b.rn>=(select count(1)-10 from alert_log a);
1SELECT *
2FROM (SELECT rownum rn,
3 a.text
4 FROM alert_log a
5 WHERE a.text LIKE 'ORA-%') b
6WHERE b.rn >=
7 (SELECT COUNT(1) - 10 FROM alert_log a WHERE a.text LIKE 'ORA-%');
8
9
10--2.利用V$DIAG_ALERT_EXT記錄歷史告警日誌的腳本以下所示:
11---drop table XB_ALERTLOG_ALL_LHR ;
12create table XB_ALERTLOG_ALL_LHR
13(
14ID NUMBER primary key,
15alert_date date,
16message_text VARCHAR2(3000),
17message_type NUMBER,
18message_level NUMBER,
19message_id VARCHAR2(67),
20message_group VARCHAR2(67),
21detailed_location VARCHAR2(163),
22problem_key VARCHAR2(67),
23record_id NUMBER,
24organization_id VARCHAR2(67),
25component_id VARCHAR2(67),
26host_id VARCHAR2(67),
27host_address VARCHAR2(49),
28client_id VARCHAR2(67),
29module_id VARCHAR2(67),
30process_id VARCHAR2(35)
31) nologging
32partition by range(alert_date)
33 interval(numtoyminterval(1,'month'))
34 (partition P201406 VALUES LESS THAN(TO_DATE('201407','YYYYMM')));
35
36--drop SEQUENCE S_XB_SQL_MONITOR_LHR;
37CREATE SEQUENCE S_XB_ALERTLOG_ALL_LHR START WITH 1 INCREMENT BY 1 cache 20;
38
39create index ind_ALERTLOG_ALL_In_Date on XB_ALERTLOG_ALL_LHR(ALERT_DATE,Record_Id) local nologging;
40
41
42---------記錄歷史告警日誌
43 CREATE PROCEDURE p_alert_log_lhr AS
44
45 v_max_recordid NUMBER;
46 v_max_date DATE;
47
48 BEGIN
49
50 SELECT MAX(a.record_id),
51 MAX(a.alert_date)
52 INTO v_max_recordid,
53 v_max_date
54 FROM XB_ALERTLOG_ALL_LHR a
55 WHERE a.alert_date >= SYSDATE - 360 / 1440 --3h'以前
56 AND a.alert_date <= SYSDATE;
57
58 INSERT INTO XB_ALERTLOG_ALL_LHR nologging
59 (ID,
60 ALERT_DATE,
61 MESSAGE_TEXT,
62 MESSAGE_TYPE,
63 MESSAGE_LEVEL,
64 MESSAGE_ID,
65 MESSAGE_GROUP,
66 DETAILED_LOCATION,
67 PROBLEM_KEY,
68 RECORD_ID,
69 ORGANIZATION_ID,
70 COMPONENT_ID,
71 HOST_ID,
72 HOST_ADDRESS,
73 CLIENT_ID,
74 MODULE_ID,
75 PROCESS_ID)
76 SELECT s_XB_ALERTLOG_ALL_LHR.Nextval,
77 to_date(to_char(a.ORIGINATING_TIMESTAMP,
78 'YYYY-MM-DD HH24:MI:SS'),
79 'YYYY-MM-DD HH24:MI:SS') alert_date,
80 a.MESSAGE_TEXT,
81 a.MESSAGE_TYPE,
82 a.MESSAGE_LEVEL,
83 a.MESSAGE_ID,
84 a.MESSAGE_GROUP,
85 a.DETAILED_LOCATION,
86 a.PROBLEM_KEY,
87 a.RECORD_ID,
88 a.ORGANIZATION_ID,
89 a.COMPONENT_ID,
90 a.HOST_ID,
91 a.HOST_ADDRESS,
92 a.CLIENT_ID,
93 a.MODULE_ID,
94 a.PROCESS_ID
95 FROM v$diag_alert_ext a
96 WHERE a.COMPONENT_ID = 'rdbms'
97 AND a.FILENAME LIKE
98 '/u01/app/oracle/diag/rdbms/orclasm/orclasm/alert/log.xml%'
99 AND a.RECORD_ID > v_max_recordid
100 AND a.ORIGINATING_TIMESTAMP >= v_max_date;
101
102 COMMIT;
103
104END p_alert_log_lhr;
105/
106
107--定時任務:
108BEGIN
109
110 DBMS_SCHEDULER.CREATE_JOB(JOB_NAME => 'job_p_alert_log_lhr',
111 JOB_TYPE => 'STORED_PROCEDURE',
112 JOB_ACTION => 'p_alert_log_lhr',
113 ENABLED => TRUE,
114 START_DATE => SYSDATE,
115 comments => '記錄歷史告警日誌,每2個小時執行一次');
116
117END;
118/
1[oracle@rhel6lhr ~]$ crontab -l
22 12 * * 1 /home/oracle/lhr/alert_log_archive.sh
3[oracle@rhel6lhr ~]$ more /home/oracle/lhr/alert_log_archive.sh
4#*************************************************************************
5# FileName :alert_log_archive.sh
6#*************************************************************************
7# Author :lhr
8# CreateDate :2014-07-16
9# blogs :http://blog.itpub.net/26736162
10# Description :this script is made the alert log archived every day
11# crontab : 2 0 * * 0 /home/oracle/lhr/alert_log_archive.sh ---sunday exec
12#*************************************************************************
13#! /bin/bash
14# these solved the oracle variable problem.
15export ORACLE_SID=orclasm
16export ORACLE_BASE=/u01/app/oracle
17mydate=`date +'%Y%m%d%H%M%S'`
18alert_log_path="$ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/trace/"
19alert_log_file="alert_$ORACLE_SID.log"
20alert_arc_file="alert_$ORACLE_SID.log""."${mydate}
21cd ${alert_log_path};
22if [ ! -e "${alert_log_file}" ]; then
23 echo "the alert log didn't exits, please check file path is correct!";
24exit;
25fi
26if [ -e ${alert_arc_file} ];then
27 echo "the alert log file have been archived!"
28else
29mv ${alert_log_file} ${alert_arc_file}
30cat /dev/null > ${alert_log_file}
31fi
32
& 說明:bash
有關告警日誌的更多內容能夠參考個人BLOG:http://blog.itpub.net/26736162/viewspace-1221559/微信
本文選自《Oracle程序員面試筆試寶典》,做者:李華榮。
網絡
詳細內容能夠添加麥老師微信或QQ私聊。oracle
● 本文做者:小麥苗,只專一於數據庫的技術,更注重技術的運用app
● 做者博客地址:http://blog.itpub.net/26736162/abstract/1/ide
● 本系列題目來源於做者的學習筆記,部分整理自網絡,如有侵權或不當之處還請諒解
● 版權全部,歡迎分享本文,轉載請保留出處
● QQ:646634621 QQ羣:618766405
● 提供OCP、OCM和高可用部分最實用的技能培訓
● 題目解答如有不當之處,還望各位朋友批評指正,共同進步
長按下圖識別二維碼或微信掃描下圖二維碼來關注小麥苗的微信公衆號:xiaomaimiaolhr,學習最實用的數據庫技術。
喜歡就點擊「好看」吧
本文分享自微信公衆號 - DB寶(lhrdba)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。