oracle工具集初探(r4笔记第8天)

时间:2022-05-04
本文章向大家介绍oracle工具集初探(r4笔记第8天),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

今天无意中看了下ORACLE_HOME/bin下面的东西,发现里面还是存在不少的东西。除了常用的sqlplus,tnsping,rman,exp/expdp,imp/impdp,sqlldr等命令外还是不少的命令可能平时不使用,但是一旦有需要还是很不错的工具集。 自己筛选了下,总结了以下的几个命令/工具。 orabase 这个命令算是一个ORACLE_BASE的简化版本。如果查看orabase文件本身,里面还是有不少的代码量的。 > orabase /opt/app/oracle/dbccbspt1 > echo $ORACLE_BASE /opt/app/oracle/dbccbspt1 -rwxr-xr-x 1 xxxx dba 3762466 Sep 5 2010 orabase oerr 这个命令很有用,但是有时候却会忘记用。 比如我们查看ora-00001的问题,可以这样输入,会给出相应的提示。有时候问题在这种层面就显而易见了。 > oerr ora 00001 00001, 00000, "unique constraint (%s.%s) violated" // *Cause: An UPDATE or INSERT statement attempted to insert a duplicate key. // For Trusted Oracle configured in DBMS MAC mode, you may see // this message if a duplicate entry exists at a different level. // *Action: Either remove the unique restriction or do not insert the key.

如果是tns的错误,比如tns-12534问题 > oerr tns 12534 12534, 00000, "TNS:operation not supported" // *Cause: An internal function received a request to perform an // operation that is not supported (on this machine). // *Action: Not normally visible to the user. For further details, turn // on tracing and reexecute the operation. If error persists, contact // Oracle Customer Support. chopt 这个命令使用需要谨慎,它可以启用/禁用某些数据库选项,除非你确实需要,要不还是很有风险的。 命令的使用方法 chopt <enable|disable> <option> options: dm = Oracle Data Mining RDBMS Files dv = Oracle Database Vault option lbac = Oracle Label Security olap = Oracle OLAP partitioning = Oracle Partitioning rat = Oracle Real Application Testing 像我们使用sqlplus登入oracle的时候,就会提示这些东西。 Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options 如果需要禁用,还是需要做充分的评估。这个操作不是一个很简单的过程,需要重新编译某些链接库。 我在本地测试了一把,最后发现要编译的时候,果断终止了。 > chopt disable rat Writing to /opt/app/oracle/xxxx/product/11.2.0/install/disable_rat.log... /usr/bin/make -f /opt/app/oracle/xxxx/product/11.2.0/rdbms/lib/ins_rdbms.mk rat_off ORACLE_HOME=/opt/app/oracle/xxxx/product/11.2.0 /usr/bin/make -f /opt/app/oracle/xxxx/product/11.2.0/rdbms/lib/ins_rdbms.mk ioracle ORACLE_HOME=/opt/app/oracle/xxxx/product/11.2.0 make: *** Deleting file `/opt/app/oracle/xxxx/product/11.2.0/rdbms/lib/oracle' make: *** wait: No child processes. Stop. make: *** Waiting for unfinished jobs.... make: *** wait: No child processes. Stop. adrci adrci是11g推出的新特性,算是对日志目录的有效管理工具,其实这些工作大家也可以通过shell脚本,命令自己定制完成。个人觉得提供的功能还是比较丰富的,不过还是根据自己的喜好来使用吧。 使用方式比较简单。直接通过help命令就一览无余了。 adrci> help HELP [topic] Available Topics: CREATE REPORT ECHO EXIT HELP HOST IPS PURGE RUN SET BASE SET BROWSER SET CONTROL SET ECHO SET EDITOR SET HOMES | HOME | HOMEPATH SET TERMOUT SHOW ALERT SHOW BASE SHOW CONTROL SHOW HM_RUN SHOW HOMES | HOME | HOMEPATH SHOW INCDIR SHOW INCIDENT SHOW PROBLEM SHOW REPORT SHOW TRACEFILE SPOOL 使用比较多的可能就是show alert,show tracefile这几个功能了。 dbfsize 这个命令的使用还是有点意思,可以读取文件头部,然后做一些基本的解析。 > dbfsize /dbccbsPT1/oracle/xxxx/orasys01/system/system01.dbf Database file: /dbccbsPT1/oracle/xxxx/orasys01/system/system01.dbf Database file type: file system Database file size: 384000 8192 byte blocks 如果文件不是数据文件,直接就报错了。 > dbfsize wa.sql wa.sql: Header block size is bad read: Success dbv 这个命令还是一个很有用的工具,在官方文档中也有详细的解释。MOS35512.1 中也有解释。 这个命令可以检验数据文件的物理结构,校验文件是否损坏等等,在online,offline的情况下都可以校验。 命令选项有以下几个。 DBVERIFY: Release 11.2.0.2.0 - Production on Wed Jan 7 21:16:21 2015 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. Keyword Description (Default) ---------------------------------------------------- FILE File to Verify (NONE) START Start Block (First Block of File) END End Block (Last Block of File) BLOCKSIZE Logical Block Size (8192) LOGFILE Output Log (NONE) FEEDBACK Display Progress (0) PARFILE Parameter File (NONE) USERID Username/Password (NONE) SEGMENT_ID Segment ID (tsn.relfile.block) (NONE) HIGH_SCN Highest Block SCN To Verify (NONE) (scn_wrap.scn_base OR scn) 自己迫不及待抓取了一个数据库系统文件测试了一把。 > dbv file=/dbccbsPT1/oracle/xxxx/orasys01/system/system01.dbf logfile=a.log DBVERIFY: Release 11.2.0.2.0 - Production on Wed Jan 7 21:16:41 2015 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. oraccbs1@ccbdbpt3:/opt/app/oracle/xxxx/product/11.2.0/bin> less a.log DBVERIFY: Release 11.2.0.2.0 - Production on Wed Jan 7 21:16:41 2015 Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved. DBVERIFY - Verification starting : FILE = /dbccbsPT1/oracle/xxxx/orasys01/system/system01.dbf DBVERIFY - Verification complete Total Pages Examined : 384000 Total Pages Processed (Data) : 219646 Total Pages Failing (Data) : 0 Total Pages Processed (Index): 108431 Total Pages Failing (Index): 0 Total Pages Processed (Other): 27414 Total Pages Processed (Seg) : 1 Total Pages Failing (Seg) : 0 Total Pages Empty : 28509 Total Pages Marked Corrupt : 0 Total Pages Influx : 0 Total Pages Encrypted : 0 Highest block SCN : 2617374659 (2566.2617374659) 还是可以看到很多比较细致的信息。更多的细节还需要精工细琢。