【探索】【oerr】对oerr出处的一点点探索

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

-- The End --
目录
相关文章
|
程序员
博文创作者都有一个拥有自己专属博客梦
经常写作的作者想必都知道,个人博客是一种历史悠久的网站形态,它能够让我们更好地表达自己的想法和思考,与读者进行互动和交流。在互联网发展的今天,个人博客仍然是一种流行的媒介,而且许多人都拥有自己的个人博客。作为程序员更是如此,要有属于自己的技术博客。
174 2
博文创作者都有一个拥有自己专属博客梦
|
网络协议 Shell PHP
原创 今日学习
原创 今日学习
111 0
原创 今日学习
|
JavaScript
原创 今日webjs学习
原创 今日webjs学习
86 0
原创 今日webjs学习
|
算法 SEO 搜索推荐
如何写好高质量的原创文章?
随着百度算法的不断升级,百度越来越重视原创文章了,但是原创文章可不单单是用工具查询的相似度为0的文章,更多的应当是可以解决用户需求,能够引发用户阅读兴趣的文章,即看了这篇文章还想下次再来你的网站进行学习。
1243 0
|
搜索推荐 SEO
如何写出高质量的原创文章
一个网站的好坏,能否有好的排名,跟网站的内容的好坏是有直接的关系的,正所谓“内容为王,外链为皇”,SEO的排名是以页面为单位的,需要足够的内容来支撑,有高质量的内容的页面才会被百度收录,能被百度收录对应的页面关键词才会有排名,关键词有排名网站才会产生流量。
671 0
|
Android开发
我的2017,阅读本文大约需要一整年
时光荏苒,恍惚间 2018 开始已经 3 天了,我知道这两天一定又是开始了一堆年终总结,当然我也不是跟风,只是去年立下的 Flag,从 2017 年开始,必须要做个年终总结。
1172 0
x3d
没想到博客园是支持@的
前面一篇文章里,提到了以前的一个小伙伴,用了类似微博的 @ 写法,没想到系统真的 @ 到他了(其实以前也 @ 过)。@someone 应该是从twitter开始流行的,微型博客中提及某人,对方更得到系统的相应提醒。
x3d
769 0
生活杂谈
小的时候,幻想自己可以靠写作为生,当里心里想的,如果写写文字就能挣钱,不用干活,那这样的生活是相当的惬意, 刚才写代码的时候,想到小时候的这个幻想,看看手头的码代码工作也是醉了,这个时间,恐怕只有那个笑出泪的表情才能表达这个时间的心态吧。 这两天在想一个事情,每个人都有病从生下来就得了一种叫死的病,每个人的病情都差不多罢了,反正每个人都要死了,何必担心。放不下的只有没有完成的任务吧
817 0