前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >剖析Oracle中oerr命令(r8笔记第70天)

剖析Oracle中oerr命令(r8笔记第70天)

作者头像
jeanron100
发布2018-03-19 15:39:17
7140
发布2018-03-19 15:39:17
举报

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. // 所以学以致用,我们也可以仿照这种方式简单定制符合自己需求的内容。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2016-04-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 杨建荣的学习笔记 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档