大补丁——PSR,通过图形界面安装即可。
小补丁——PSU,通过opatch工具安装。
OPatch 命令
先看一个官网的Oracle OPatch 的说明:
Oracle Software Patching Using Opatch
http://download.oracle.com/docs/cd/B19306_01/em.102/b16227/oui8_opatch.htm
从9.2版开始,Oracle公司实现了个别补丁安装工具opatch. opatch使用一个称为inventory的系统数据结构(严格说是与oui共享inventory),集中管理所有已安装的个别补丁;个别补丁的安装和卸载都使用opatch命令完成,冲突检测也由opatch在安装时自动完成;提供列表命令可以很方便得到已安装个别补丁的信息。
10g(10.1和10.2)版本中,opatch作为一个标准工具,在安装时自动安装。(安装在$ORACLE_HOME/OPatch下。)而对于9.2版,需要从metalink下载opatch.无论是哪一个版本,系统中是否已经安装opatch,在使用之前,应从metalink下载最新版本的opatch.很遗憾,由于系统实现的问题,10.2使用的opatch与之前版本(10.1和9.2)使用的opatch不兼容,不能混用,这一点必须注意。
opatch是使用perl编写的脚本程序(其中也使用JAVA API)。使用的perl版本是5.6版,虽然在5.6之前的版本中也可运行,但应尽可能安装5.6或以上的版本的perl. 对于DBA来说一个好消息是,如果安装9.2版软件时保留了HTTP服务器,则在$ORACLE_HOME/Apache下会自动安装perl.(10g会自动安装配置perl和opatch.)
1 opatch命令存放位置
该命令的存放位置在$ORACLE_HOME下的OPatch目录下。
-bash-3.2$ pwd
/u01/oracle/oracle/product/10.2.0/db_1/OPatch
-bash-3.2$ ls
docs emdpatch.pl jlib opatch opatch.ini opatch.pl
-bash-3.2$ ls -lrt
total 44
-rw-r--r-- 1 oracle oinstall 18107 Apr 18 2005 emdpatch.pl
-rw-r--r-- 1 oracle oinstall 2193 Jun 1 2005 opatch.pl
-rwxr-xr-x 1 oracle oinstall 5672 Jun 1 2005 opatch
drwxr-x--- 2 oracle oinstall 4096 Apr 21 13:24 jlib
drwxr-x--- 2 oracle oinstall 4096 Apr 21 13:24 docs
-rw-r--r-- 1 oracle oinstall 49 Apr 21 13:24 opatch.ini
2 使用“-help”参数可以获得opatch命令的帮助信息
-bash-3.2$ ./opatch --help
Invoking OPatch 10.2.0.1.0
Oracle interim Patch Installer version 10.2.0.1.0
Copyright (c) 2005, Oracle Corporation. All rights reserved..
Oracle Home : /u01/oracle/oracle/product/10.2.0/db_1
Central Inventory : /u01/oracle/oraInventory
from : /u01/oracle/oracle/product/10.2.0/db_1/oraInst.loc
OPatch version : 10.2.0.1.0
OUI version : 10.2.0.1.0
OUI location : /u01/oracle/oracle/product/10.2.0/db_1//oui
Log file location : /u01/oracle/oracle/product/10.2.0/db_1/cfgtoollogs/opatch/opatch-2010_Aug_09_03-05-40-CST_Mon.log
Usage: opatch [ -help ] [ -r[eport] ] [ command ]
command := apply
lsinventory
query
rollback
version
<global_arguments> := -help Displays the help message for the command.
-report Print the actions without executing (deprecated).
example:
'opatch -help'
'opatch apply -help'
'opatch lsinventory -help'
'opatch rollback -help'
OPatch succeeded.
这个是10.2.0.1版本的opatch. 在10.2.0.4 版本的opatch命令与之前的又不同,它又添加了几个命令。
-bash-3.2$ ./opatch --help
Invoking OPatch 11.1.0.6.6
Oracle Interim Patch Installer version 11.1.0.6.6
Copyright (c) 2009, Oracle Corporation. All rights reserved.
Usage: opatch [ -help ] [ -r[eport] ] [ command ]
command := apply
lsinventory
napply
nrollback
rollback
query
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 napply -help'
'opatch nrollback -help'
'opatch rollback -help'
'opatch prereq -help'
'opatch util -help'
OPatch succeeded.
官网上对命令的一些解释:
apply |
Installs an interim patch. Refer to "apply Command" for more information. |
napply |
Installs n number of patches (hence napply). Refer to "napply Command" for more information. |
auto |
Applies Oracle Clusterware patches. Refer to "auto Command" for more information. |
lsinventory |
Lists what is currently installed on the system. Refer to "lsinventory Command" for more information. |
query |
Queries a given patch for specific details. Refer to "query Command" for more information. |
rollback |
Removes an interim patch. Refer to "rollback Command" for more information. |
nrollback |
Removes n number of patches (hence nrollback). Refer to "nrollback Command" for more information. |
version |
Prints the current version of the patch tool. Refer to "version Command" for more information. |
在$ORACLE_HOME/OPatch/docs目录下,用指南文件(Users_Guide.txt),其中有详细的命令格式和使用示例,可以参考。
Opatch执行操作时,除在屏幕输出结果外,还生成日志文件。日志文件的路径和文件名格式如下:
$ORACLE_HOME/.patch_storage/< patch_id >/< action >-< patch_id >_< mm-dd-yyyy_hh-mi-ss>.log
其中“patch_id”是Oracle技术支持部门为个别补丁分配的编号。
3 opatch安装个别补丁示例:
以Patch 5689937 为例。
3.1 patch下载
从metalink下载补丁的压缩文件p5689937_10201_LINUX.zip.将此文件解压缩至某一目录中。解压缩后,这一补丁的所有文件都在子目录5689937下,目录名就是个别补丁的补丁号,opatch依据目录名获得信息,所以一定不要重命名子目录。
3.2 安装patch
进入patch文件5689937 目录,在patch的目录下面有一个readme的安装文档,里面有安装步骤和一些问题的处理方法。
3.2.1 关闭数据库和监听
Shut down all instances and listeners associated with the Oracle home that you are updating.
3.2.2. 进入patch目录,运行opatch apply命令
-bash-3.2$ cd p5689937_10201_LINUX/
-bash-3.2$ ls
5689937 patchmd.xml README.html
-bash-3.2$ cd 5689937/
-bash-3.2$ ls
custom etc files README.txt
-bash-3.2$ pwd
/mnt/p5689937_10201_LINUX/5689937
-bash-3.2$ export PATH=$PATH:/usr/ccs/bin
-bash-3.2$ $ORACLE_HOME/OPatch/opatch apply
3.2.3 启动实例,运行相关脚本
-bash-3.2$ cd $ORACLE_HOME/cpu/CPUJan2007/ -- 要进入这个目录才能找到脚本
-bash-3.2$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 9 04:48:19 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 281018368 bytes
Fixed Size 1218968 bytes
Variable Size 83887720 bytes
Database Buffers 192937984 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SQL> @catcpu.sql
如果catcpu.sql 脚本报任何无效对象,执行如下脚本:
SQL> @?/rdbms/admin/utlrp.sql
可以用如下SQL 检查无效对象:
SQL> SELECT OBJECT_NAME FROM DBA_OBJECTS WHERE STATUS= 'INVALID';
3.3 用inventory 命令查看已经安装的patch
-bash-3.2$ $ORACLE_HOME/OPatch/opatch lsinventory
Invoking OPatch 10.2.0.1.0
Oracle interim Patch Installer version 10.2.0.1.0
Copyright (c) 2005, Oracle Corporation. All rights reserved..
Oracle Home : /u01/oracle/oracle/product/10.2.0/db_1
Central Inventory : /u01/oracle/oraInventory
from : /u01/oracle/oracle/product/10.2.0/db_1/oraInst.loc
OPatch version : 10.2.0.1.0
OUI version : 10.2.0.1.0
OUI location : /u01/oracle/oracle/product/10.2.0/db_1//oui
Log file location : /u01/oracle/oracle/product/10.2.0/db_1/cfgtoollogs/opatch/opatch-2010_Aug_09_04-55-55-CST_Mon.log
Lsinventory Output file location : /u01/oracle/oracle/product/10.2.0/db_1/cfgtoollogs/opatch/lsinv/lsinventory-2010_Aug_09_04-55-55-CST_Mon.txt
--------------------------------------------------------------------------------
Installed Top-level Products (1):
Oracle Database 10g 10.2.0.1.0
There are 1 products installed in this Oracle Home.
Interim patches (1) :
Patch 5689937 : applied on Mon Aug 09 04:43:27 CST 2010
Created on 8 Jan 2007, 11:48:31 hrs US/Eastern
Bugs fixed:
4671216, 4925103, 4604970, 4616376, 5689937, 4288876, 5225798, 5694720
4754888, 4750469, 4369235, 4751931, 4966716, 5049080, 5242648, 4348230
5490846, 4630549, 5490936, 5049088
--------------------------------------------------------------------------------
OPatch succeeded.
或者用$ORACLE_HOME/OPatch/opatch lsinventory –detail 命令查看详细。
4 卸载 opatch
4.1 关闭实例和监听
SQL> shutdown immediate
4.2 执行opatch命令
-bash-3.2$ cd $ORACLE_HOME/OPatch/
-bash-3.2$ ./opatch rollback -id 5689937
4.3 启动实例,执行catcpu_rollback.sql脚本
-bash-3.2$ cd $ORACLE_HOME/cpu/CPUJan2007/
-bash-3.2$ sqlplus /nolog
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Aug 9 05:04:19 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 281018368 bytes
Fixed Size 1218968 bytes
Variable Size 109053544 bytes
Database Buffers 167772160 bytes
Redo Buffers 2973696 bytes
Database mounted.
Database opened.
SQL> @catcpu_rollback.sql -- 这个脚本在patch的安装目录里也有
如果在运行中出现无效对象,运行如下脚本:
SQL> @?/rdbms/admin/utlrp.sql
检查无效对象:
SQL> SELECT OBJECT_NAME FROM DBA_OBJECTS WHERE STATUS = 'INVALID';
关于Patch的说明就到此。 在后说明一点。 有时我们的生产库遇到一个问题,但是又不能十分确定是否是某个bug的时候,可以先考虑打patch看一下,如果解决了更好,如果不能解决,把patch删掉即可。 这样可以把问题控制在可控的范围内,避免把问题扩大化。
文档转自Dave的博客:http://blog.csdn.net/tianlesoftware/article/details/5809526