Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3215306
  • 博文数量: 710
  • 博客积分: 14546
  • 博客等级: 上将
  • 技术积分: 6738
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-30 10:20
文章分类

全部博文(710)

文章存档

2016年(1)

2014年(7)

2013年(22)

2012年(227)

2011年(322)

2009年(119)

2008年(12)

分类: Oracle

2011-08-01 15:31:43

oerr可以在Linux和UNIX操作系统上查询简短的报错信息的含义,可以很好的辅助排查Oracle故障。
这个小文儿介绍一下这个工具的使用方法,然后从oerr脚本中找点有意思的信息。

1.oerr的使用方法
[oracle@BJS ~]$ oerr ora 12571
12571, 00000, "TNS:packet writer failure"
// *Cause: An error occurred during a data send.
// *Action: Not normally visible to the user. For further details, turn
// on tracing and reexecute the operation. If error persists, contact
// Oracle Customer Support.

2.使用which命令查询oerr工具的位置
secooler@testdb /home/oracle$ which oerr
/oracle/app/oracle/product/10.2.0/db_1/bin/oerr

3.看一下这个脚本文件记录的内容
secooler@testdb /home/oracle$ vi /oracle/app/oracle/product/10.2.0/db_1/bin/oerr
1 #!/bin/sh
2 #
3 # $Id: oerr 28-aug-2001.15:35:03 mkrohan Exp $
4 # Copyright (c) 1994, 2001, Oracle Corporation. All rights reserved.
5 #
6 # Usage: oerr facility error
7 #
8 # This shell script. is used to get the description and the cause and actio    n
9 # of an error from a message text file when a list of error numbers are pa    ssed
10 # to it. It supports different language environments and errors from diff    erent
11 # facilities.
12 #
13
14 #
15 # Turn on script. tracing if, requested
16 [ "$ORACLE_TRACE" = "T" ] && set -x
17
18 #
19 # If ORACLE_HOME is not set, we will not be able to locate
20 # the message text file.
21 if [ ! "$ORACLE_HOME" ]
22 then
23         echo "ORACLE_HOME not set. Please set ORACLE_HOME and try again."     1>&2
24         exit 1
25 fi
26
27 #
28 # Ignore user locale
29 LC_ALL=C
30 export LC_ALL
31
32 #
33 # Definition script. "constants"
34 Facilities_File=$ORACLE_HOME/lib/facility.lis
35
36 #
37 # Check script. usage
38 if [ "$#" != "2" ]
39 then
40         exec 1>&2
41         echo 'Usage: oerr facility error'
42         echo
43         echo 'Facility is identified by the prefix string in the error mes    sage.'
44         echo 'For example, if you get ORA-7300, "ora" is the facility and     "7300"'
45         echo 'is the error. So you should type "oerr ora 7300".'
46         echo
47         echo 'If you get LCD-111, type "oerr lcd 111", and so on.'
48         exit 1
49 fi
50
51 #
52 # Pickup the command line arguments
53 Facility="$1"
54 Code="$2"
55
56 #
57 # Get the facility information from the oerr data file
58 Fac_Info=`grep -i "^${Facility}:" $Facilities_File 2> /dev/null`
59 if [ $? -ne 0 ]
60 then
61         echo "oerr: Unknown facility '$Facility'" 1>&2
62         exit 1
63 fi
64
65 #
66 # Parse the components from the Fac_Info string into Shell variables
67 eval `echo "$Fac_Info" | awk -F: '{
68                 if (index ($3, "*") == 0)
69                         printf ("Facility=%s\n", $3);
70                 else
71                         printf ("Facility=%s\n", $1);
72                 printf ("Component=%s\n", $2);
73                 }'`
74 if [ -z "$Facility" -o -z "$Component" ]
75 then
76         echo "oerr: Invalid facilities entry '$Fac_Info'" 1>&2
77         exit 1
78 fi
79
80 #
81 # The message file searched is always the US English file
82 Msg_File=$ORACLE_HOME/$Component/mesg/${Facility}us.msg
83 if [ ! -r $Msg_File ]
84 then
85         echo "oerr: Cannot access the message file $Msg_File" 1>&2
86         exit 1
87 fi
88
89 #
90 # Search the message file for the error code, printing the message text
91 # and any following comments which should give the cause and action for
92 # the error.
93 awk "BEGIN { found = 0; }
94         /^[0]*$Code/    { found = 1; print ; next;}
95         /^\/\//         { if (found) { print; } next; }
96                         { if (found) { exit; } }" $Msg_File
97
98 exit 0

4.从这个脚本文件中能获得很多有意思的东西,抛个砖,指出一处。其他的大家慢慢发掘
我感兴趣的是脚本中的第82行
82 Msg_File=$ORACLE_HOME/$Component/mesg/${Facility}us.msg
这里似乎暗示着我们,所有的检索信息都是来自于这些*.msg文件

我们在ORACLE_HOME目录中使用find命令查找与oraus关键字相关的文件,这里得到了两个文件
secooler@testdb /home/oracle$ find $ORACLE_HOME -name mesg | xargs find ora | grep -i oraus
/oracle/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msg
/oracle/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msb

在使用head命令查看部分信息后发现,oraus.msg文件非常的有意思,这个文件中记录了各种与ora相关的错误信息,oerr工具正是检索这个文件中的相应信息返回到屏幕中的。
oraus.msb文件是一个二进制文件,对我们的帮助不大。

通过上面的挖掘,我们得到了所有与命令“oerr ora *****”相关的报错信息的出处了,换一种说法就是:我们可以直接通过oraus.msg文件来得到与ora相关的报错信息汇总。

通过这个文件直接得到12571错误描述信息
$ vi oraus.msg
搜索12571得到如下信息,可以看到和使用oerr ora 12571得到的信息一致
12571, 00000, "TNS:packet writer failure"
// *Cause: An error occurred during a data send.
// *Action: Not normally visible to the user. For further details, turn
// on tracing and reexecute the operation. If error persists, contact
// Oracle Customer Support.
/

有兴趣的话可以导航到$ORACLE_HOME/rdbms/mesg/目录,查看*.msg类文件,可以得到更多有趣的信息。

5.最后我们使用"sh -x"的方式看一下这个脚本文件真实的执行过程,这个过程更加直接,比直接读脚本来的直接很多
[oracle@BJS ~]$ sh -x oerr ora 12571
+ '[' '' = T ']'
+ '[' '!' /oracle/app/oracle/product/10.2.0/db_1 ']'
+ LC_ALL=C
+ export LC_ALL
+ Facilities_File=/oracle/app/oracle/product/10.2.0/db_1/lib/facility.lis
+ '[' 2 '!=' 2 ']'
+ Facility=ora
+ Code=12571
++ grep -i '^ora:' /oracle/app/oracle/product/10.2.0/db_1/lib/facility.lis
+ Fac_Info='ora:rdbms:*:'
+ '[' 0 -ne 0 ']'
++ echo 'ora:rdbms:*:'
++ awk -F: '{
                if (index ($3, "*") == 0)
                        printf ("Facility=%s\n", $3);
                else
                        printf ("Facility=%s\n", $1);
                printf ("Component=%s\n", $2);
                }'
+ eval Facility=ora Component=rdbms
++ Facility=ora
++ Component=rdbms
+ '[' -z ora -o -z rdbms ']'
+ Msg_File=/oracle/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msg
+ '[' '!' -r /oracle/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msg ']'
+ awk 'BEGIN { found = 0; }
        /^[0]*12571/    { found = 1; print ; next;}
        /^\/\//         { if (found) { print; } next; }
                        { if (found) { exit; } }' /oracle/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msg
12571, 00000, "TNS:packet writer failure"
// *Cause: An error occurred during a data send.
// *Action: Not normally visible to the user. For further details, turn
// on tracing and reexecute the operation. If error persists, contact
// Oracle Customer Support.
+ exit 0


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