阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

剖析Oracle中oerr命令

104次阅读
没有评论

共计 3189 个字符,预计需要花费 8 分钟才能阅读完成。

Oralce 中的命令非常丰富,oerr 命令是一个不错的辅助工具,很多看起来没有眉目的错误代码,可以让 DBA 很快定位问题的缘由,我们根本不需要去记有哪些 ORA 错误,除非那些错误已经完全和你的工作分不开。

绝大多数的命令都是二进制的形式,比如 sqlplus 我们可一窥其中的奥妙,oerr 是一个 shell 脚本,而且实现原理也不难,我们来剖析一下,看看这个工具的设计思想。

首先这个工具位于 $Oracle_HOME/bin 下,直接看还看不出是个 shell 脚本。

[oracle@db117 ~]$ ll $ORACLE_HOME/bin/oerr
-rwxr-xr-x 1 oracle oinstall 2567 Apr 23  2014 /U01/app/oracle/product/11.2.0.4/bin/oerr
但是我就是喜欢折腾,所以无意中就打开了这个文件。可以看到这个脚本的注释如下:
# 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.
当然脚本的完整内容也没有多少行,我们来简单看看,有一个配置文件 facility.lis
Facilities_File=$ORACLE_HOME/lib/facility.lis
需要从这个配置文件中取得相应的 component,比如我们使用命令 oerr ora 12345, 则 ora 就是第一个参数,根据这个参数可以得到接下来需要使用的 component 值。
脚本里面有如下一行类似的内容,我们带入参数 ora,当然还可以输入 tns 等等。
Fac_Info=`grep -i “^${Facility}:” $Facilities_File 2> /dev/null`
我们转换一下,可以看到得到的 component 是 rdbms
[oracle@db117 ~]$ grep -i “^ora:” $ORACLE_HOME/lib/facility.lis
ora:rdbms:*:
至于这一行内容的解释,在文件中也可以轻松找到。
#
# The entries in this file are colon separated defining, for each
# facility (field 1), the component name (field 2), the “real” facility
# name for facilities with aliases (field 3) with a value of “*” for
# facilities without renamings and an optional facility description
# (field 4)
#
#      facility:component:rename:description
#

里面的内容如下:
acfs:usm:*:
acfsk:usm:*:
advm:usm:acfs:
advmk:usm:*:
amd:cwmlite:*:
amdu:rdbms:*:
当然这只是开始,错误信息的文件在一个指定的文件中,比如 component 是 rdbms,则错误信息的文件为 $ORACLE_HOME/rdbms/mesg
[oracle@db117 ~]$ cd $ORACLE_HOME/rdbms/mesg
而错误信息的文件也是有规律的,和 ora 相关的一个文件,oraus.msg 也是大体这样的格式。
[oracle@db117 mesg]$ ll ora*us*msg
-rw-r–r– 1 oracle oinstall 4976647 Apr 23  2014 oraus.msg

比方这个时候我们移步到错误信息的文件中,找到了下面两行错误信息。
64477, 00000, “Multiple token tables are not supported.”
// *Cause:  An attempt was made to create a new token table. If encountered
//          during an import, a critical patch was possibly missing on the
//          export database.
// *Action:  Use the default token table. If encountered during an import,
//          apply the appropriate patch on the export database and try the
//          export and import again.

64621, 00000, “SQL statement length (%s) exceeds maximum allowed length (%s)”
// *Cause:  An attempt was made to issue a SQL statement that exceeded the
//          maximum allowed length of a statement.
// *Action: Modify the SQL statement or the views to which it refers to fit
//          within the maximum length or split the SQL statement.
//
这个时候怎么去解析读取这个文件的呢,
首先就是解析错误编码,比如输入错误编码 64621,我们也可以输入 064621 等,这个地方都会使用 sed 来先转换一下,保证能够找到完全匹配的内容。
Code=`echo 64621|/bin/sed ‘s/^[0]*//’`
[oracle@db117 bin]$ echo 64621|/bin/sed ‘s/^[0]*//’
64621
[oracle@db117 bin]$ echo 064621|/bin/sed ‘s/^[0]*//’
64621
假设这个时候我们就看 64621 的错误信息,这个时候就可以使用 awk 来读取文件的内容。Oracle 的调用方式类似下面的形式。
Code=64621
[oracle@db117 bin]$ awk “BEGIN {found = 0;}
      /^[0]*$Code/    {found = 1; print ; next;}
      /^\/\//        {if (found) {print;} next; }
                      {if (found) {exit;} }” $ORACLE_HOME/rdbms/mesg/oraus.msg
64621, 00000, “SQL statement length (%s) exceeds maximum allowed length (%s)”
// *Cause:  An attempt was made to issue a SQL statement that exceeded the
//          maximum allowed length of a statement.
// *Action: Modify the SQL statement or the views to which it refers to fit
//          within the maximum length or split the SQL statement.
//
所以学以致用,我们也可以仿照这种方式简单定制符合自己需求的内容。

更多 Oracle 相关信息见 Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-04/130538.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计3189字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中