现在的位置: 首页 > 综合 > 正文

安装oraInventory和使用opatch给Oracle打补丁

2013年10月03日 ⁄ 综合 ⁄ 共 4051字 ⁄ 字号 评论关闭

  opatch是给Oracle补丁的工具,命令使用起来简单方便。他默认地址在$ORACLE_HOME/OPatch/opatch,直接运行会显示所有可用命令。

> $ORACLE_HOME/OPatch/opatch
Invoking OPatch 10.2.0.3.0

Oracle interim Patch Installer version 10.2.0.3.0
Copyright (c) 2005, Oracle Corporation.  All rights reserved..


 Usage: opatch [ -help ] [ -r[eport] ] [ command ]

            command := apply
                       lsinventory
                       query
                       rollback
                       version
                       prereq
                       util

 <global_arguments> := -help       Displays the help message for the command.
                       -report     Print the actions without executing.

 example:
   'opatch -help'
   'opatch apply -help'
   'opatch lsinventory -help'
   'opatch rollback -help'
   'opatch prereq -help'
   'opatch util -help'
  


OPatch succeeded.

但是对于初学者,有几个错误很容易发生。

1.没有oraInst.loc文件

这其实是一个简单的配置文件,用来定义oraInventory的位置。他的默认地址是在/var/opt/oracle/oraInst.loc。

他的格式为:

> cat /var/opt/oracle/oraInst.loc
inventory_loc=/export/home/oracle/products/10203/oraInventory
inst_group=dba

如果没有这个文件,当我们查看当前有哪些patch时会出报104错:

> opatch lsinventory
Invoking OPatch 10.2.0.3.0

Oracle interim Patch Installer version 10.2.0.3.0
Copyright (c) 2005, Oracle Corporation.  All rights reserved..


Oracle Home       : /export/home/oracle/products/10203
Central Inventory : n/a
   from           :
OPatch version    : 10.2.0.3.0
OUI version       : 10.2.0.3.0
OUI location      : /export/home/oracle/products/10203/oui
Log file location : n/a

OPatch cannot find a valid oraInst.loc file to locate Central Inventory.

OPatch failed with error code 104

当这个文件不在默认的路径时,我们可以加“-invPtrLoc ”来指明oraInst.loc的地址:

$ORACLE_HOME/OPatch/opatch lsinventory  -invPtrLoc /var/opt/oracle/oraInst.loc.2

2.没有正确/完整安装oraInventory(Central Inventory)

此时,虽然/var/opt/oracle/oraInst.loc文件存在,并且假设其指向的oraInventory没有被正确或者完全安装,那么opatch lsinventory时会报如下错:

> opatch lsinventory
Invoking OPatch 10.2.0.3.0

Oracle interim Patch Installer version 10.2.0.3.0
Copyright (c) 2005, Oracle Corporation.  All rights reserved..


Oracle Home       : /export/home/oracle/products/10203
Central Inventory : /export/home/oracle/products/10203/myinventory
   from           : /var/opt/oracle/oraInst.loc
OPatch version    : 10.2.0.3.0
OUI version       : 10.2.0.3.0
OUI location      : /export/home/oracle/products/10203/oui
Log file location : /export/home/oracle/products/10203/cfgtoollogs/opatch/opatch2010-01-27_20-06-34PM.log

List of Homes on this system:

Inventory load failed... OPatch cannot load inventory for the given Oracle Home.
Possible causes are:
   Oracle Home dir. path does not exist in Central Inventory
   Oracle Home is a symbolic link
   Oracle Home inventory is corrupted
LsInventorySession failed: OracleHomeInventory::load() gets null oracleHomeInfo

OPatch failed with error code 73

此时,我们需要安装metalink Doc id 556834.1来重建oraInventory(Central Inventory)。

对于类unix系统,我们只需很简单的执行如下命令重建即可(注意替换你自己的ORACLE_HOME和ORACLE_HOME_NAME):

> ./runInstaller -silent -ignoreSysPrereqs -attachHome ORACLE_HOME="/export/home/oracle/products/10203" ORACLE_HOME_NAME="home1"
Starting Oracle Universal Installer...

No pre-requisite checks found in oraparam.ini, no system pre-requisite checks will be executed.

>>> Ignoring required pre-requisite failures. Continuing...

The inventory pointer is located at /var/opt/oracle/oraInst.loc
The inventory is located at /export/home/oracle/products/10203/oraInventory
'AttachHome' was successful.

   

    在以上两个错误解决之后(或者你根本就没遇到),opatch lsinventory 可以正确看到当前binary已经安装了哪些patch。

其实还有一种办法,前提是你从来只是安装patch,没有rollback过patch,那么你可以 cd $ORACLE_HOME/.patch_storage ,然后ls -altr查看所有的patch。

但是如果你rollback了一个patch,用这种办法还是会看到这个patch,所以,最好的办法还是通过opatch lsinventory来查看。

    下面以我在10203环境中打patch 7706062为例:

1.在metalink上下载patch p7706062_10203_SOLARIS64.zip

2.unzip p7706062_10203_SOLARIS64.zip

3.cd 7706062

4.$ORACLE_HOME/OPatch/opatch apply(注意,在停掉所有使用当前binary的数据库之后再进行)

此时,我们遇到问题:

Patch(es) 5605370 conflict with the patch currently being installed (7706062).

If you continue, patch(es) 5605370 will be rolled back and the new patch (7706062) will be installed.

If a merge of the new patch (7706062) and the conflicting patch(es) (5605370) is required, contact Oracle Support Services and request a Merged patch.

因为两个patch冲突,所以要么2选1,要么找oracle请求一个merged patch。(你自己选择。。。)

这里我强行安装patch 7706062会导致patch 5605370 rollback.

5.如果你后悔了,也可以rollback这个patch:

$ORACLE_HOME/OPatch/opatch rollback -id 7706062

并且记得重新安装前面被rollback的patch 5605370 。

抱歉!评论已关闭.