oerr使用

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

1.oerr的使用方法
[oracle@BJS ~]$ oerr ora 12571
12571, 00000, "TNS:packet writer failure"
// *Cause: An error occurred during adatasend.
// *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
/u01/app/oracle/product/10.2/db10g/bin/oerr

3.看一下这个脚本文件记录的内容
secooler@testdb /home/oracle$ vi /u01/app/oracle/product/10.2/db10g/bin/oerr

 

[java] view plaincopy
"oerr" 98 lines, 2365 characters
#!/bin/sh
#
# $Id: oerr 28-aug-2001.15:35:03 mkrohan Exp $
# Copyright (c) 1994, 2001, Oracle Corporation. All rights reserved.
#
# Usage: oerr facility error
#
# This shell script is used to get the description and the cause and action
# of an error from a message text file when a list of error numbers are passed
# to it. It supports different language environments and errors from different
# facilities.
#

#
# Turn on script tracing if, requested
[ "$ORACLE_TRACE" = "T" ] && set -x

#
# If ORACLE_HOME is not set, we will not be able to locate
# the message text file.
if [ ! "$ORACLE_HOME" ]
then
echo "ORACLE_HOME not set. Please set ORACLE_HOME and try again." 1>&2
exit 1
fi

#
# Ignore user locale
LC_ALL=C
export LC_ALL

#
# Definition script "constants"
Facilities_File=$ORACLE_HOME/lib/facility.lis

#
# Check script usage
if [ "$#" != "2" ]
then
exec 1>&2
echo 'Usage: oerr facility error'
echo
echo 'Facility is identified by the prefix string in the error message.'
echo 'For example, if you get ORA-7300, "ora" is the facility and "7300"'
echo 'is the error. So you should type "oerr ora 7300".'
echo
echo 'If you get LCD-111, type "oerr lcd 111", and so on.'
exit 1
fi

#
# Pickup the command line arguments
Facility="$1"
Code="$2"

#
# Get the facility information from the oerr data file
Fac_Info=`grep -i "^${Facility}:" $Facilities_File 2> /dev/null`
if [ $? -ne 0 ]
then
echo "oerr: Unknown facility '$Facility'" 1>&2
exit 1
fi

#
# Parse the components from the Fac_Info string into Shell variables
eval `echo "$Fac_Info" | awk -F: '{
if (index ($3, "*") == 0)
printf ("Facility=%s\n", $3);
else
printf ("Facility=%s\n", $1);
printf ("Component=%s\n", $2);
}'`
if [ -z "$Facility" -o -z "$Component" ]
then
echo "oerr: Invalid facilities entry '$Fac_Info'" 1>&2
exit 1
fi

#
# The message file searched is always the US English file
Msg_File=$ORACLE_HOME/$Component/mesg/${Facility}us.msg
if [ ! -r $Msg_File ]
then
echo "oerr: Cannot access the message file $Msg_File" 1>&2
exit 1
fi

#
# Search the message file for the error code, printing the message text
# and any following comments which should give the cause and action for
# the error.
awk "BEGIN { found = 0; }
/^[0]*$Code/ { found = 1; print ; next;}
/^\/\// { if (found) { print; } next; }
{ if (found) { exit; } }" $Msg_File

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
/u01/app/oracle/product/10.2.0/db_1/rdbms/mesg/oraus.msg
/u01/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 ']'
+ '[' '!' /u01/app/oracle/product/10.2.0/db_1 ']'
+ LC_ALL=C
+ export LC_ALL
+ Facilities_File=/u01/app/oracle/product/10.2.0/db_1/lib/facility.lis
+ '[' 2 '!=' 2 ']'
+ Facility=ora
+ Code=12571
++ grep -i '^ora:' /u01/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 /u01/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

posted @ 2015-11-26 15:58  defiwy  阅读(111)  评论(0)    收藏  举报