Oracle 11gR2是目前新系统应用比较广泛的Oracle版本,根据官方路线图,11.2.0.4是11g末期的一个版本。应该说,11gR2之后,Oracle直接提供了完整升级版本,可以直接安装高版本的数据库系统,不需要从基础版本逐步升级。
本篇主要记录以11.2.0.4为基础,单实例条件下Oracle补丁安装过程。
1、补丁包和环境介绍
首先确定数据库版本,笔者以一台全新安装Oracle 11gR2单实例进行安装,具体版本为11.2.0.4。
SQL> select * from v$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
PL/SQL Release 11.2.0.4.0 - Production
CORE 11.2.0.4.0 Production
TNS for Linux: Version 11.2.0.4.0 - Production
NLSRTL Version 11.2.0.4.0 – Production
进行操作的补丁文件如下:
[root@XXX-PROD-DB upload]# cd patch/
[root@XXX-PROD-DB patch]# ls -l
total 282772
-rw-r--r--. 1 root root 407030 Jul 15 09:03 p19852360_112040_Generic.zip
-rw-r--r--. 1 root root 71580583 Jul 15 09:03 p20299013_112040_Linux-x86-64.zip
-rw-r--r--. 1 root root 12335412 Jul 15 09:03 p20299015_112040_Linux-x86-64.zip
-rw-r--r--. 1 root root 40486165 Jul 15 09:03 p20406239_112040_Linux-x86-64.zip
-rw-r--r--. 1 root root 112087303 Jul 15 09:02 p20834611_112040_Linux-x86-64.zip
-rw-r--r--. 1 root root 52648436 Jul 15 09:02 p6880880_112000_Linux-x86-64.zip
注意:其中p6880880_112000_Linux-x86-64.zip是新版本OPatch,一般而言打补丁都需要更新最新的OPatch。
2、升级OPatch组件
首先需要以覆盖方式升级OPatch组件。
[oracle@XXX-PROD-DB ~]$ cd $ORACLE_HOME
[oracle@XXX-PROD-DB dbhome_1]$ ls -l | grep OPatch
drwxr-xr-x. 8 oracle oinstall 4096 Jul 16 10:08 OPatch
备份OPatch目录,并用解压zip文件替换。
[oracle@XXX-PROD-DB dbhome_1]$ cp /upload/patch/p6880880_112000_Linux-x86-64.zip $ORACLE_HOME
[oracle@XXX-PROD-DB dbhome_1]$ ls -l | grep p6880880_112000_Linux-x86-64.zip
-rw-r--r--. 1 oracle oinstall 52648436 Aug 4 08:42 p6880880_112000_Linux-x86-64.zip
[oracle@XXX-PROD-DB dbhome_1]$ mv OPatch OPatch_BK
[oracle@XXX-PROD-DB dbhome_1]$ ls -l | grep OPatch
drwxr-xr-x. 8 oracle oinstall 4096 Jul 16 10:08 OPatch_BK
解压OPatch文件。
[root@XXX-PROD-DB ~]# cd /u01/app/oracle/product/11.2.0/dbhome_1
[root@XXX-PROD-DB dbhome_1]# ls -l | grep p6880880_112000_Linux-x86-64.zip
-rw-r--r--. 1 oracle oinstall 52648436 Aug 4 08:42 p6880880_112000_Linux-x86-64.zip
[root@XXX-PROD-DB dbhome_1]# unzip p6880880_112000_Linux-x86-64.zip
[root@XXX-PROD-DB dbhome_1]# ls -l | grep OPatch
drwxr-x---. 10 root root 4096 Mar 31 17:10 OPatch
drwxr-xr-x. 8 oracle oinstall 4096 Jul 16 10:08 OPatch_BK
[root@XXX-PROD-DB dbhome_1]# chown -R oracle:oinstall OPatch
[root@XXX-PROD-DB dbhome_1]# ls -l | grep OPatch
drwxr-x---. 10 oracle oinstall 4096 Mar 31 17:10 OPatch
drwxr-xr-x. 8 oracle oinstall 4096 Jul 16 10:08 OPatch_BK
OPatch是一个命令脚本工具,为方便起见,可以将其加入到PATH环境变量中。
[oracle@XXX-PROD-DB dbhome_1]$ cd ~
[oracle@XXX-PROD-DB ~]$ vi .bash_profile
(篇幅原因,有省略……)
ORACLE_SID=XXXCDB
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
PATH=$PATH:$ORACLE_HOME/bin:/u01/app/oracle/product/11.2.0/dbhome_1/OPatch
export ORACLE_SID
export ORACLE_BASE
export ORACLE_HOME
export PATH
".bash_profile" 23L, 409C written
查看OPatch版本。
[oracle@XXX-PROD-DB ~]$ opatch version
OPatch Version: 11.2.0.3.10
OPatch succeeded.
2、补丁19852360_112040
补丁19852360_112040是一个简单的补丁,主要是针对JDBC相关的补丁类型。原则上,不需要进行关库操作。
[root@XXX-PROD-DB patch]# unzip p19852360_112040_Generic.zip
Archive: p19852360_112040_Generic.zip
creating: 19852360/
inflating: 19852360/README.txt
creating: 19852360/files/
creating: 19852360/files/jdbc/
(篇幅原因,有省略……)
inflating: 19852360/etc/xml/GenericActions.xml
inflating: 19852360/etc/xml/ShiphomeDirectoryStructure.xml
进入解压目录,注意:要确保补丁文件的文件权限设置。
[oracle@XXX-PROD-DB ~]$ cd /upload/patch/
[oracle@XXX-PROD-DB patch]$ ls -l
total 282776
drwxr-xr-x. 4 oracle oinstall 4096 Oct 20 2014 19852360
-rw-r--r--. 1 root root 407030 Jul 15 09:03 p19852360_112040_Generic.zip
[oracle@XXX-PROD-DB patch]$ cd 19852360/
[oracle@XXX-PROD-DB 19852360]$ ls -l
total 20
drwxr-xr-x. 4 oracle oinstall 4096 Oct 20 2014 etc
drwxr-xr-x. 3 oracle oinstall 4096 Oct 20 2014 files
-rw-rw-r--. 1 oracle oinstall 10858 Oct 28 2014 README.txt
[oracle@XXX-PROD-DB 19852360]$
注意:无论DBA经验多丰富,在进行补丁的时候,一定要参考每个补丁的readme.txt文件,遵循官方步骤进行操作。用成熟技术、用官方步骤是我们确保成功的重要原则。
首先,进行补丁先决条件检查。
[oracle@XXX-PROD-DB 19852360]$ opatch prereq CheckConflictAgainstOHWithDetail -ph ./
Oracle Interim Patch Installer version 11.2.0.3.10
Copyright (c) 2015, Oracle Corporation. All rights reserved.
PREREQ session
Oracle Home : /u01/app/oracle/product/11.2.0/dbhome_1
Central Inventory : /u01/app/oraInventory
from : /u01/app/oracle/product/11.2.0/dbhome_1/oraInst.loc
OPatch version : 11.2.0.3.10
OUI version : 11.2.0.4.0
Log file location : /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/opatch2015-08-04_10-22-39AM_1.log
Invoking prereq "checkconflictagainstohwithdetail"
Prereq "checkConflictAgainstOHWithDetail" passed.
OPatch succeeded.
没有发现问题,可以直接进行补丁。
[oracle@XXX-PROD-DB 19852360]$ opatch apply
Oracle Interim Patch Installer version 11.2.0.3.10
Copyright (c) 2015, Oracle Corporation. All rights reserved.
Oracle Home : /u01/app/oracle/product/11.2.0/dbhome_1
Central Inventory : /u01/app/oraInventory
from : /u01/app/oracle/product/11.2.0/dbhome_1/oraInst.loc
OPatch version : 11.2.0.3.10
OUI version : 11.2.0.4.0
Log file location : /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/19852360_Aug_04_2015_10_21_09/apply2015-08-04_10-21-09AM_1.log
Applying interim patch '19852360' to OH '/u01/app/oracle/product/11.2.0/dbhome_1'
Verifying environment and performing prerequisite checks...
All checks passed.
Provide your email address to be informed of security issues, install and
initiate Oracle Configuration Manager. Easier for you if you use your My
Oracle Support Email address/User Name.
Visit http://www.oracle.com/support/policies.html for details.
Email address/User Name:
You have not provided an email address for notification of security issues.
Do you wish to remain uninformed of security issues ([Y]es, [N]o) [N]: Y
Backing up files...
Patching component oracle.dbjava.jdbc, 11.2.0.4.0...
Patching component oracle.dbjava.ic, 11.2.0.4.0...
Verifying the update...
Patch 19852360 successfully applied
Log file location: /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/19852360_Aug_04_2015_10_21_09/apply2015-08-04_10-21-09AM_1.log
OPatch succeeded.
3、补丁20299013_112040
解压补丁文件:
[root@XXX-PROD-DB patch]# unzip p20299013_112040_Linux-x86-64.zip
inflating: 20299013/18522509/files/lib/libserver11.a/qerel.o
inflating: 20299013/18522509/files/lib/libserver11.a/knahs.o
(篇幅原因,有省略……)
inflating: 20299013/18522509/etc/config/actions.xml
inflating: 20299013/18522509/etc/config/inventory.xml
inflating: PatchSearch.xml
设置owner权限。
[root@XXX-PROD-DB patch]# chown -R oracle:oinstall 20299013/
[root@XXX-PROD-DB patch]# ls -l
total 282840
drwxr-xr-x. 4 oracle oinstall 4096 Oct 20 2014 19852360
drwxrwxr-x. 8 oracle oinstall 4096 Mar 4 18:30 20299013
补丁20299013_112040是一个补丁集合,多个经过验证的安全补丁集合防止,是可以统一进行补丁操作的。
[oracle@XXX-PROD-DB 20299013]$ ls -l
total 88
drwxr-xr-x. 4 oracle oinstall 4096 Mar 4 18:30 17478514
drwxr-xr-x. 4 oracle oinstall 4096 Mar 4 18:30 18031668
drwxr-xr-x. 4 oracle oinstall 4096 Mar 4 18:30 18522509
drwxr-xr-x. 4 oracle oinstall 4096 Mar 4 18:30 19121551
drwxrwxr-x. 4 oracle oinstall 4096 Mar 4 18:30 19769489
drwxrwxr-x. 4 oracle oinstall 4096 Mar 4 18:30 20299013
-rw-r--r--. 1 oracle oinstall 3068 Mar 4 18:30 patchmd.xml
-rw-rw-r--. 1 oracle oinstall 54747 Apr 12 10:40 README.html
-rw-r--r--. 1 oracle oinstall 21 Mar 4 18:30 README.txt
进行先决性检查。
[oracle@XXX-PROD-DB 20299013]$ opatch prereq CheckConflictAgainstOHWithDetail -ph ./
Oracle Interim Patch Installer version 11.2.0.3.10
Copyright (c) 2015, Oracle Corporation. All rights reserved.
PREREQ session
Oracle Home : /u01/app/oracle/product/11.2.0/dbhome_1
Central Inventory : /u01/app/oraInventory
from : /u01/app/oracle/product/11.2.0/dbhome_1/oraInst.loc
OPatch version : 11.2.0.3.10
OUI version : 11.2.0.4.0
Log file location : /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/opatch2015-08-04_10-28-53AM_1.log
Invoking prereq "checkconflictagainstohwithdetail"
Prereq "checkConflictAgainstOHWithDetail" passed.
OPatch succeeded.
验证通���,说明当前系统安装补丁和将要安装补丁之间没有冲突。但是,执行apply的时候就有问题。
[oracle@XXX-PROD-DB 20299013]$ opatch apply
Oracle Interim Patch Installer version 11.2.0.3.10
Copyright (c) 2015, Oracle Corporation. All rights reserved.
Oracle Home : /u01/app/oracle/product/11.2.0/dbhome_1
Central Inventory : /u01/app/oraInventory
from : /u01/app/oracle/product/11.2.0/dbhome_1/oraInst.loc
OPatch version : 11.2.0.3.10
OUI version : 11.2.0.4.0
Log file location : /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/opatch2015-08-04_10-29-25AM_1.log
Verifying environment and performing prerequisite checks...
Prerequisite check "CheckActiveFilesAndExecutables" failed.
The details are:
Following executables are active :
/u01/app/oracle/product/11.2.0/dbhome_1/bin/oracle
/u01/app/oracle/product/11.2.0/dbhome_1/lib/libclntsh.so.11.1
UtilSession failed: Prerequisite check "CheckActiveFilesAndExecutables" failed.
Log file location: /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/opatch2015-08-04_10-29-25AM_1.log
OPatch failed with error code 73
报错信息中包括了日志内容,一旦出现Oracle错误,各种日志是进行诊断的最好方法。
[root@XXX-PROD-DB patch]# cd /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/
[root@XXX-PROD-DB opatch]# ls -l
total 36
drwxr-xr-x. 2 oracle oinstall 4096 Aug 4 10:21 19852360_Aug_04_2015_10_21_09
drwxr-xr-x. 2 oracle oinstall 4096 Aug 4 10:06 lsinv
-rw-r--r--. 1 oracle oinstall 2050 Aug 4 10:06 opatch2015-08-04_10-06-22AM_1.log
-rw-r--r--. 1 oracle oinstall 1665 Aug 4 10:22 opatch2015-08-04_10-22-39AM_1.log
-rw-r--r--. 1 oracle oinstall 2021 Aug 4 10:28 opatch2015-08-04_10-28-53AM_1.log
-rw-r--r--. 1 oracle oinstall 10540 Aug 4 10:29 opatch2015-08-04_10-29-25AM_1.log
-rw-r--r--. 1 oracle oinstall 1872 Aug 4 10:29 opatch_history.txt
[root@INTCTL-PROD-DB opatch]# ls -l | grep 2015-08-04_10-29-25
-rw-r--r--. 1 oracle oinstall 10540 Aug 4 10:29 opatch2015-08-04_10-29-25AM_1.log
--日志片段:
[Aug 4, 2015 10:29:31 AM] Finish fuser command /sbin/fuser /u01/app/oracle/product/11.2.0/dbhome_1/bin/proc at Tue Aug 04 10:29:31 CST 2015
[Aug 4, 2015 10:29:31 AM] Start fuser command /sbin/fuser /u01/app/oracle/product/11.2.0/dbhome_1/lib/liborasdkbase.so.11.1 at Tue Aug 04 10:29:31 CST 2015
[Aug 4, 2015 10:29:31 AM] Finish fuser command /sbin/fuser /u01/app/oracle/product/11.2.0/dbhome_1/lib/liborasdkbase.so.11.1 at Tue Aug 04 10:29:31 CST 2015
[Aug 4, 2015 10:29:31 AM] Start fuser command /sbin/fuser /u01/app/oracle/product/11.2.0/dbhome_1/bin/wrap at Tue Aug 04 10:29:31 CST 2015
[Aug 4, 2015 10:29:31 AM] Finish fuser command /sbin/fuser /u01/app/oracle/product/11.2.0/dbhome_1/bin/wrap at Tue Aug 04 10:29:31 CST 2015
[Aug 4, 2015 10:29:31 AM] Start fuser command /sbin/fuser /u01/app/oracle/product/11.2.0/dbhome_1/bin/e2eme at Tue Aug 04 10:29:31 CST 2015
[Aug 4, 2015 10:29:31 AM] Finish fuser command /sbin/fuser /u01/app/oracle/product/11.2.0/dbhome_1/bin/e2eme at Tue Aug 04 10:29:31 CST 2015
[Aug 4, 2015 10:29:31 AM] OUI-67073:UtilSession failed: Prerequisite check "CheckActiveFilesAndExecutables" failed.
[Aug 4, 2015 10:29:31 AM] Finishing UtilSession at Tue Aug 04 10:29:31 CST 2015
[Aug 4, 2015 10:29:31 AM] Log file location: /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/opatch2015-08-04_10-29-25AM_1.log
[Aug 4, 2015 10:29:31 AM] Stack Description: java.lang.RuntimeException: Prerequisite check "CheckActiveFilesAndExecutables" failed.
[Aug 4, 2015 10:29:31 AM] StackTrace: oracle.opatch.OPatchSessionHelper.runApplyPrereqs(OPatchSessionHelper.java:5717)
[Aug 4, 2015 10:29:31 AM] StackTrace: oracle.opatch.opatchutil.NApply.process(NApply.java:697)
[Aug 4, 2015 10:29:31 AM] StackTrace: oracle.opatch.opatchutil.OUSession.napply(OUSession.java:1082)
[Aug 4, 2015 10:29:31 AM] StackTrace: sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[Aug 4, 2015 10:29:31 AM] StackTrace: sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[Aug 4, 2015 10:29:31 AM] StackTrace: sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[Aug 4, 2015 10:29:31 AM] StackTrace: java.lang.reflect.Method.invoke(Method.java:592)
[Aug 4, 2015 10:29:31 AM] StackTrace: oracle.opatch.UtilSession.process(UtilSession.java:317)
[Aug 4, 2015 10:29:31 AM] StackTrace: oracle.opatch.OPatchSession.main(OPatchSession.java:2575)
[Aug 4, 2015 10:29:31 AM] StackTrace: oracle.opatch.OPatch.main(OPatch.java:626)
经过分析,认为是Oracle数据库和监听器启动状态。安装补丁的时候,最好还是能够停机进行。
[oracle@XXX-PROD-DB 20299013]$ lsnrctl stop
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 04-AUG-2015 10:37:25
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
The command completed successfully
[oracle@INTCTL-PROD-DB 20299013]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.4.0 Production on Tue Aug 4 10:37:32 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> quit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
进行OPatch Apply操作。
[oracle@XXX-PROD-DB 20299013]$ opatch apply
Oracle Interim Patch Installer version 11.2.0.3.10
Copyright (c) 2015, Oracle Corporation. All rights reserved.
Oracle Home : /u01/app/oracle/product/11.2.0/dbhome_1
Central Inventory : /u01/app/oraInventory
from : /u01/app/oracle/product/11.2.0/dbhome_1/oraInst.loc
OPatch version : 11.2.0.3.10
OUI version : 11.2.0.4.0
Log file location : /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/opatch2015-08-04_10-38-47AM_1.log
Verifying environment and performing prerequisite checks...
OPatch continues with these patches: 17478514 18031668 18522509 19121551 19769489 20299013
(篇幅原因,有省略……)
Composite patch 20299013 successfully applied.
Log file location: /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/opatch2015-08-04_10-38-47AM_1.log
OPatch succeeded.
补丁成功。
注意:此时完成的是数据库软件、数据库实例的升级。但是数据库对象却没有升级。之后重启数据库,要进行脚本升级执行。
[oracle@XXX-PROD-DB 20299013]$ sqlplus /nolog
SQL*Plus: Release 11.2.0.4.0 Production on Tue Aug 4 10:41:37 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.
Total System Global Area 5227814912 bytes
Fixed Size 2262368 bytes
Variable Size 1140853408 bytes
Database Buffers 4076863488 bytes
Redo Buffers 7835648 bytes
Database mounted.
Database opened.
执行脚本。
SQL> @?/rdbms/admin/catbundle.sql psu apply
SQL> COMMIT;
Commit complete.
SQL> SPOOL off
SQL> SET echo off
Check the following log file for errors:
/u01/app/oracle/cfgtoollogs/catbundle/catbundle_PSU_INTCDB_APPLY_2015Aug04_10_42_39.log
查看补丁内容信息:
[oracle@XXX-PROD-DB 20299013]$ opatch lsinventory
Oracle Interim Patch Installer version 11.2.0.3.10
Copyright (c) 2015, Oracle Corporation. All rights reserved.
Oracle Home : /u01/app/oracle/product/11.2.0/dbhome_1
Central Inventory : /u01/app/oraInventory
from : /u01/app/oracle/product/11.2.0/dbhome_1/oraInst.loc
OPatch version : 11.2.0.3.10
OUI version : 11.2.0.4.0
Log file location : /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/opatch2015-08-04_10-45-21AM_1.log
Lsinventory Output file location : /u01/app/oracle/product/11.2.0/dbhome_1/cfgtoollogs/opatch/lsinv/lsinventory2015-08-04_10-45-21AM.txt
--------------------------------------------------------------------------------
Local Machine Information::
Hostname: localhost
ARU platform id: 226
ARU platform description:: Linux x86-64
Installed Top-level Products (1):
Oracle Database 11g 11.2.0.4.0
There are 1 products installed in this Oracle Home.
Interim patches (2) :
Patch 20299013 : applied on Tue Aug 04 10:40:12 CST 2015
Unique Patch ID: 18573940
Patch description: "Database Patch Set Update : 11.2.0.4.6 (20299013)"
Created on 4 Mar 2015, 02:27:44 hrs PST8PDT
Sub-patch 19769489; "Database Patch Set Update : 11.2.0.4.5 (19769489)"
Sub-patch 19121551; "Database Patch Set Update : 11.2.0.4.4 (19121551)"
(篇幅原因,有省略……)
18674047, 17672719, 18856999, 12364061, 18783224, 17851160, 17546761
Patch 19852360 : applied on Tue Aug 04 10:21:38 CST 2015
Unique Patch ID: 18170553
Created on 20 Oct 2014, 08:17:43 hrs PST8PDT
Bugs fixed:
19852360
--------------------------------------------------------------------------------
OPatch succeeded.
其余补丁方式相同,不予累述。
4、总结
补丁升级是所有DBA都需要面对的日常操作。及时进行数据库补丁,可以尽最大可能减少数据库运行风险,提高数据库运行安全度。
: