剖析Oracle中oerr命令

简介: Oralce中的命令非常丰富,oerr命令是一个不错的辅助工具,很多看起来没有眉目的错误代码,可以让DBA很快定位问题的缘由,我们根本不需要去记有哪些ORA错误,除非那些错误已经完全和你的工作分不开。
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.
//
所以学以致用,我们也可以仿照这种方式简单定制符合自己需求的内容。
目录
相关文章
|
2月前
|
Oracle 关系型数据库 分布式数据库
PolarDB常见问题之PolarDB(Oracle兼容版) 执行命令报错如何解决
PolarDB是阿里云推出的下一代关系型数据库,具有高性能、高可用性和弹性伸缩能力,适用于大规模数据处理场景。本汇总囊括了PolarDB使用中用户可能遭遇的一系列常见问题及解答,旨在为数据库管理员和开发者提供全面的问题指导,确保数据库平稳运行和优化使用体验。
|
24天前
|
SQL Oracle 关系型数据库
Oracle spool格式化数据命令
在这个示例中,通过设置不同的 `SET`命令参数,你可以控制输出的格式,包括每页行数、每行字符数、列分隔符等。你也可以使用其他的 `SET`命令参数来进一步定制输出格式。
14 0
|
25天前
|
SQL Oracle 关系型数据库
Oracle SQL*Plus的SPOOL命令:数据库世界的“录像机”
【4月更文挑战第19天】`SQL*Plus`的`SPOOL`命令是Oracle数据库中的“录像机”,能记录所有操作和输出。它在用户开始“SPOOL ON”时启动,记录SQL查询、输出、错误信息等。完成后,“SPOOL OFF”停止记录并生成日志文件,便于回顾和检查。日志文件可自定义保存位置和命名,支持多文件录制,方便分类管理。无论数据分析、SQL脚本编写还是日常维护,`SPOOL`都是强大的工具,值得一试!
|
8月前
|
SQL Oracle 关系型数据库
Oracle杂谈二 SQL*PLUS命令的使用大全
Oracle杂谈二 SQL*PLUS命令的使用大全
33 0
|
3月前
|
Oracle 关系型数据库
oracle 19c 搭建dataguard 简要命令
通过service 完成dg 搭建。
54 0
|
4月前
|
SQL Oracle 关系型数据库
Linux环境下oracle切换用户并查询数据库命令
Linux环境下oracle切换用户并查询数据库命令
|
5月前
|
SQL Oracle 关系型数据库
Oracle 常用命令大全
Oracle 常用命令大全
|
10月前
|
Oracle 关系型数据库
win7下oracle命令启动 发生系统错误 5
win7下oracle命令启动 发生系统错误 5
|
11月前
|
SQL XML Oracle
oracle命令的缩写原型单词方便记忆总结
$ORACLE_HOME/bin下的utilities解释 Binary First Available Description adapters (7.3.4) Installed Network Adapters agentctl 9.0.1 Agent Control Utility agtctl 8.1.5 Agent Control Utility bulkmodify
103 0
|
11月前
|
Oracle 关系型数据库 Linux
5分钟学会在Linux上安装Oracle和一条命令创建数据库
在Linux上安装Oracle软件的过程相当复杂,让很多初学者望而却步。但在Oracle 18c以后Oracle推出了使用rpm包安装Oracle数据库软件的安装方式
256 0