Oracle 11g 新特性 -- 热补丁(Online Patching )

在Oracle 11g中提出了online patch(也叫hot patch)的特性;Hot patching允许我们在实例始终在线的情况下安装,启用或禁用一个修复补丁(fix)或者诊断补丁(diagnostic patches)。

使用热补丁可以安装、启用和禁用正在运行的活动Oracle 实例上的bug 修复或诊断补丁程序。使用热补丁是可在应用热补丁程序时避免停机的建议解决方案。Oracle 提供了使用opatch 命令行实用程序对任何Oracle 数据库进行热补丁的功能。如果代码的更改范围和复杂性都较小(例如,诊断补丁程序或小型bug 修复),则可提供热补丁程序。

热补丁的优点:

1) 无停机时间,不中断业务

(2) 安装和卸载速度极快

(3) 与OPatch 集成:

检测冲突

在补丁程序清单中列出

在RAC 环境中工作

(4) 虽然不改变磁盘上的

Oracle二进制文件,但热补丁程序在实例关闭和启动时都保持有效。

热补丁注意事项

(1)可能不是所有平台上都有热补丁程序。当前在以下平台上有热补丁程序:

– Linux x86

– Linux x86-64

– Solaris SPARC64

(2)要消耗一些额外的内存。

– 确切的内存数取决于:

— 补丁程序的大小

— 当前运行的Oracle 进程数

– 最小内存数:每个Oracle 进程大约占一个OS 页面

如:一个操作系统(OS) 页面在Linux x86 上一般为4 KB,在和Solaris SPARC64 上为8 KB。

在平均大约一千个Oracle 进程同时运行的情况下,这意味着一个小型的热补丁程序大约额外占用4 MB 内存。

(3) 在每个Oracle 进程安装或卸载热补丁程序之前,可能会有一段极短的延迟(几秒)。

(4) 并非所有bug 修复和诊断补丁程序都可用作热补丁程序。

极大部分诊断补丁程序可作为热补丁程序提供。对于bug 修复,则具体取决于其性质。并非每个bug 修复或诊断补丁程序都可用作热补丁程序。但热补丁工具的长期目标是为关键补丁程序更新提供热补丁功能。

(5) 不能在停机时间使用热补丁程序。

(6) 如果可能有停机时间,则应以常规补丁程序方式安装所有相关的bug 修复。

Online Patch 操作示例

测试环境是11.2.0.3:

SQL> select * from v$version;

BANNER

--------------------------------------------------------------------------------

Oracle Database 11g Enterprise EditionRelease 11.2.0.3.0 - 64bit Production

PL/SQL Release 11.2.0.3.0 - Production

CORE   11.2.0.3.0      Production

TNS for Linux: Version 11.2.0.3.0 -Production

NLSRTL Version 11.2.0.3.0 – Production

Google了一下,找了一个对应版本的onlinepatch:

Oracle online patching for bug 13817131(backport for ORA-7445 near ksfqfcrx()+X during RMAN backups)

http://jakub.wartak.pl/blog/?p=624

这里用online patch:13817131的相关操作为例。

3.1 解压缩:

[oracle@dave u01]$ unzipp13817131_112030_Linux-x86-64.zip

Archive: p13817131_112030_Linux-x86-64.zip

  creating: 13817131/

  creating: 13817131/etc/

  creating: 13817131/etc/xml/

 inflating: 13817131/etc/xml/ShiphomeDirectoryStructure.xml 

 inflating: 13817131/etc/xml/GenericActions.xml 

  creating: 13817131/etc/config/

 inflating: 13817131/etc/config/inventory.xml 

 inflating: 13817131/etc/config/actions.xml 

 inflating: 13817131/etc/config/deploy.xml 

  creating: 13817131/online/

  creating: 13817131/online/files/

  creating: 13817131/online/files/hpatch/

 inflating: 13817131/online/files/hpatch/bug13817131.pch 

  creating: 13817131/online/etc/

  creating: 13817131/online/etc/xml/

 inflating: 13817131/online/etc/xml/GenericActions.xml 

 inflating: 13817131/online/etc/xml/ShiphomeDirectoryStructure.xml 

  creating: 13817131/online/etc/config/

 inflating: 13817131/online/etc/config/actions.xml 

 inflating: 13817131/online/etc/config/deploy.xml 

 inflating: 13817131/online/etc/config/inventory.xml 

  creating: 13817131/files/

  creating: 13817131/files/lib/

  creating: 13817131/files/lib/libserver11.a/

 inflating: 13817131/files/lib/libserver11.a/ksfq.o 

 inflating: 13817131/README.txt    

3.2 查看Patch 类型

3.2.1 用树形结构看一下:如果是online patch,会有online 的目录:

[oracle@dave u01]$ ls

13817131 dave       dave2.trc  p13817131_112030_Linux-x86-64.zip  rcopy.sh     rename.sh

app      dave1.trc  nohup.out  rcopy.out                          rcopy.sh.out

[oracle@dave u01]$ tree 13817131

13817131

|-- etc

|  |-- config

|  |   |-- actions.xml

|  |   |-- deploy.xml

|  |   `-- inventory.xml

|  `-- xml

|      |-- GenericActions.xml

|      `-- ShiphomeDirectoryStructure.xml

|-- files

|  `-- lib

|      `-- libserver11.a

|          `-- ksfq.o

|-- online

|  |-- etc

|  |   |-- config

|  |   |   |-- actions.xml

|  |   |   |-- deploy.xml

|  |   |   `-- inventory.xml

|  |   `-- xml

|  |       |-- GenericActions.xml

|  |       `--ShiphomeDirectoryStructure.xml

|  `-- files

|      `-- hpatch

|          `-- bug13817131.pch

`-- README.txt

12 directories, 13 files

3.2.2 使用opatch 查看patch 类型:

[oracle@dave u01]$ mv 13817131/u01/app/oracle/product/11.2.0/db_1/OPatch

[oracle@dave u01]$ cd/u01/app/oracle/product/11.2.0/db_1/OPatch

[oracle@dave OPatch]$ ls

13817131 emdpatch.pl  jlib  opatch     opatch.ini  opatchprereqs

docs     fmw          ocm   opatch.bat opatch.pl

[oracle@dave OPatch]$ ./opatch query 13817131 -all

Invoking OPatch 11.2.0.1.7

Oracle Home       : /u01/app/oracle/product/11.2.0/db_1

Central Inventory : /u01/app/oraInventory

  from           : /etc/oraInst.loc

OPatch version    : 11.2.0.1.7

OUI version       : 11.2.0.3.0

Log file location :/u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2012-10-09_19-00-40ÏÂÎç.log

--------------------------------------------------------------------------------

 Patch created on 25 Sep 2012, 08:46:37 hrsPST8PDT

 Needto shutdown Oracle instances: true

 Patch is roll-backable: true

 Patch is a "Patchset Update": false

 Patch is a rolling patch: true

 Patch has sql related actions: false

 Patch is an online patch: false

 Patch is a portal patch: false

 Patch is an "auto-enabled" patch:false

 Listof platforms supported:

  226: Linux x86-64

 Listof bugs to be fixed:

  13817131: OAM ORA-7445-[KSFQFCRX()+812] [SIGSEGV] [ADDR 0X8 ]

 Thispatch is a "singleton" patch.

 Thispatch belongs to the "db" product family

 Listof executables affected:

  ORACLE_HOME/bin/oracle

 Listof optional components:

  oracle.rdbms:  11.2.0.3.0

 Listof optional actions:

  Update /u01/app/oracle/product/11.2.0/db_1/lib/libserver11.a with/ksfq.o

   cd/u01/app/oracle/product/11.2.0/db_1/rdbms/lib

    ; make -f ins_rdbms.mk ioracleORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1

 Possible XML representation of the patch:

<ONEOFF REF_ID="13817131"ROLLBACK="T" XML_INV_LOC="oneoffs/13817131/"ACT_INST_VER="11.2.0.3.0" INSTALL_TIME="2012.Oct.09 19:00:40CST">

  <DESC></DESC>

  <REF_LIST>

     <REF NAME="oracle.rdbms" VER="11.2.0.3.0"HOME_IDX="0"/>

  </REF_LIST>

  <BUG_LIST>

    <BUG>13817131</BUG>

  </BUG_LIST>

  <FILE_LIST/>

</ONEOFF>

--------------------------------------------------------------------------------

OPatch succeeded.

这里显示为False。 用opatch is_online_patch 查看:

[oracle@dave OPatch]$ ./opatch query -is_online_patch 13817131

Invoking OPatch 11.2.0.1.7

Oracle Home       : /u01/app/oracle/product/11.2.0/db_1

Central Inventory : /u01/app/oraInventory

  from           : /etc/oraInst.loc

OPatch version    : 11.2.0.1.7

OUI version       : 11.2.0.3.0

Log file location :/u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2012-10-09_19-02-47ÏÂÎç.log

--------------------------------------------------------------------------------

 Patch is an online patch: false

OPatch succeeded.

这里显示的还是为False,但实际上,我们的Patch 确实是online 的patch。

3.3 应用Patch并确认Online Patch 对内存的消耗:

安装online patch需要额外的消耗一些内存资源,所以这里我们验证一下:

--查看pmon 进程的内存消耗:

[oracle@dave 13817131]$ ps -ef|grep pmon|grep-v grep

oracle   2118     1  0 15:15 ?        00:00:13 ora_pmon_dave

[oracle@dave 13817131]$ pmap -d 2118 |tail -20

00007fb4ef13a000    1020 ----- 0000000000289000 008:00003libnnz11.so

00007fb4ef239000     264 rwx-- 0000000000288000 008:00003libnnz11.so

00007fb4ef27b000      12 rwx-- 0000000000000000 000:00000   [ anon ]

00007fb4ef28d000       4 rwxs- 0000000000000000 008:00003hc_dave.dat

00007fb4ef28e000       8 rwx-- 0000000000000000 000:00000   [ anon ]

00007fb4ef290000     864 r-x-- 0000000000000000 008:00003libskgxp11.so

00007fb4ef368000    1024 ----- 00000000000d8000 008:00003libskgxp11.so

00007fb4ef468000       8 rwx-- 00000000000d8000 008:00003libskgxp11.so

00007fb4ef46a000     392r-x-- 0000000000000000 008:00003 libcell11.so

00007fb4ef4cc000    1024 ----- 0000000000062000 008:00003libcell11.so

00007fb4ef5cc000      40 rwx-- 0000000000062000 008:00003libcell11.so

00007fb4ef5d6000       8 rwx-- 0000000000000000 000:00000   [ anon ]

00007fb4ef5d8000       4 r-x-- 0000000000000000 008:00003libodmd11.so

00007fb4ef5d9000    1024 ----- 0000000000001000 008:00003libodmd11.so

00007fb4ef6d9000       4 rwx-- 0000000000001000 008:00003libodmd11.so

00007fb4ef6da000       4 rwx-- 0000000000000000 000:00000   [ anon ]

00007ffff0261000     132 rwx-- 0000000000000000 000:00000   [ stack ]

00007ffff03f6000       4 r-x-- 0000000000000000 000:00000   [ anon ]

ffffffffff600000       4 r-x-- 0000000000000000 000:00000   [ anon ]

mapped: 958080K    writeable/private: 8056K    shared: 720900K

--安装Patch:

oracle@dave 13817131]$ opatch apply online -connectString dave:sys:oracle

Invoking OPatch 11.2.0.1.7

Oracle 中间补丁程序安装程序版本11.2.0.1.7

版权所有 (c) 2011, Oracle Corporation。保留所有权利。

Oracle Home       : /u01/app/oracle/product/11.2.0/db_1

Central Inventory : /u01/app/oraInventory

  from           : /etc/oraInst.loc

OPatch version    : 11.2.0.1.7

OUI version       : 11.2.0.3.0

Log file location :/u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2012-10-09_19-10-51下午.log

补丁程序只应在 '-all_nodes' 模式下应用/回退。

将 RAC 模式转换为'-all_nodes' 模式。

Applying interim patch '13817131' to OH'/u01/app/oracle/product/11.2.0/db_1'

Verifying environment and performingprerequisite checks...

是否继续? [y|n]

y

User Responded with: Y

All checks passed.

Backing up files...

正在为组件 oracle.rdbms, 11.2.0.3.0 打补丁...

The patch will be installed on activedatabase instances.

正在数据库 'dave' 上安装和启用联机补丁程序 'bug13817131.pch'。

Patch 13817131 successfully applied

Log file location:/u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2012-10-09_19-10-51下午.log

OPatch succeeded.

--查看alert log:

Tue Oct 09 19:11:05 2012

Patch file bug13817131.pch is out of syncwith oracle binary; performing fixup

Patch file bug13817131.pch has been syncedwith oracle binary

Patch bug13817131.pchInstalled - Update #1

Patch bug13817131.pchEnabled - Update #2

Tue Oct 09 19:11:07 2012

Online patch bug13817131.pch has beeninstalled

Online patch bug13817131.pch has beenenabled

--再次查看pmon 进程的内存:

[oracle@dave trace]$ ps -ef|grep pmon|grep-v grep

oracle   2118     1  0 15:15 ?        00:00:14 ora_pmon_dave

[oracle@dave trace]$ pmap -d 2118|tail -20

00007fb4ef239000     264 rwx-- 0000000000288000 008:00003libnnz11.so

00007fb4ef27b000      12 rwx-- 0000000000000000 000:00000   [ anon ]

00007fb4ef28c000       4 r-x-- 000000000c955000 008:00003oracle

00007fb4ef28d000       4 rwxs- 0000000000000000 008:00003hc_dave.dat

00007fb4ef28e000       8 rwx-- 0000000000000000 000:00000   [ anon ]

00007fb4ef290000     864 r-x-- 0000000000000000 008:00003libskgxp11.so

00007fb4ef368000    1024 ----- 00000000000d8000 008:00003libskgxp11.so

00007fb4ef468000       8 rwx-- 00000000000d8000 008:00003libskgxp11.so

00007fb4ef46a000     392r-x-- 0000000000000000 008:00003 libcell11.so

00007fb4ef4cc000    1024 ----- 0000000000062000 008:00003libcell11.so

00007fb4ef5cc000      40 rwx-- 0000000000062000 008:00003libcell11.so

00007fb4ef5d6000       8 rwx-- 0000000000000000 000:00000   [ anon ]

00007fb4ef5d8000       4 r-x-- 0000000000000000 008:00003libodmd11.so

00007fb4ef5d9000    1024 ----- 0000000000001000 008:00003libodmd11.so

00007fb4ef6d9000       4 rwx-- 0000000000001000 008:00003libodmd11.so

00007fb4ef6da000       4 rwx-- 0000000000000000 000:00000   [ anon ]

00007ffff0261000     132 rwx-- 0000000000000000 000:00000   [ stack ]

00007ffff03f6000       4 r-x-- 0000000000000000 000:00000   [ anon ]

ffffffffff600000       4 r-x-- 0000000000000000 000:00000   [ anon ]

mapped: 964344K    writeable/private: 8068K    shared: 720900K

--安装Patch 之前是:

mapped: 958080K    writeable/private: 8056K    shared: 720900K。

private 内存增加了 8k。

--并且安装之后,从pmon 进程的内存中,可以看到多出如下3个库文件:

 [oracle@davetrace]$ pmap -d 2118|grep 13817131

00007fb4ecf66000     168 r-x-- 0000000000000000 008:00003bug13817131.so

00007fb4ecf90000    1020 ----- 000000000002a000 008:00003bug13817131.so

00007fb4ed08f000      12 rwx-- 0000000000029000 008:00003bug13817131.so

3.4 使用oradebug 来禁用patch

在1.7 小节提到了2种Oracle 不推荐的,使用oradebug 来禁用online patch的方法。 我们这里测试一下。

(1)使用Oradebug

SQL> oradebug patch list

Patch File Name                                   State

================                                =========

bug13817131.pch                                  ENABLED

SQL> oradebugpatch disable bug13817131.pch

Statement processed.

SQL> oradebug patch list

Patch File Name                                   State

================                                =========

bug13817131.pch                                  DISABLED

注意,这种方法不会释放安装onlinepatch 时消耗的额外内存。

[oracle@dave trace]$ pmap -d 2118|tail-20    

00007fb4ef239000     264 rwx-- 0000000000288000 008:00003libnnz11.so

00007fb4ef27b000      12 rwx-- 0000000000000000 000:00000   [ anon ]

00007fb4ef28c000       4 r-x-- 000000000c955000 008:00003oracle

00007fb4ef28d000       4 rwxs- 0000000000000000 008:00003hc_dave.dat

00007fb4ef28e000       8 rwx-- 0000000000000000 000:00000   [ anon ]

00007fb4ef290000     864 r-x-- 0000000000000000 008:00003libskgxp11.so

00007fb4ef368000    1024 ----- 00000000000d8000 008:00003libskgxp11.so

00007fb4ef468000       8 rwx-- 00000000000d8000 008:00003libskgxp11.so

00007fb4ef46a000     392 r-x-- 0000000000000000 008:00003libcell11.so

00007fb4ef4cc000    1024 ----- 0000000000062000 008:00003libcell11.so

00007fb4ef5cc000      40 rwx-- 0000000000062000 008:00003libcell11.so

00007fb4ef5d6000       8 rwx-- 0000000000000000 000:00000   [ anon ]

00007fb4ef5d8000       4 r-x-- 0000000000000000 008:00003libodmd11.so

00007fb4ef5d9000    1024 ----- 0000000000001000 008:00003libodmd11.so

00007fb4ef6d9000       4 rwx-- 0000000000001000 008:00003libodmd11.so

00007fb4ef6da000       4 rwx-- 0000000000000000 000:00000   [ anon ]

00007ffff0261000     132 rwx-- 0000000000000000 000:00000   [ stack ]

00007ffff03f6000       4 r-x-- 0000000000000000 000:00000   [ anon ]

ffffffffff600000       4 r-x-- 0000000000000000 000:00000   [ anon ]

mapped: 964344K    writeable/private: 8068K    shared: 720900K

--使用oradebug enable patch:

SQL> oradebug patch enablebug13817131.pch

Statement processed.

SQL> oradebug patch list

Patch File Name                                   State

================                                =========

bug13817131.pch                                  ENABLED

(2)关闭实例并移除配置文件

Shutting the instancedown and removing the orapatch*.cfg file. Afterstopping the instance do the following:

cd $ORACLE_HOME/hpatch
rm orapatch$ORACLE_SID.cfg

--这里强调是关闭实例在操作,否则可能会出现其他意外情况。


Removing the orapatch*.cfg removes all of the online patches currentlyinstalled for the instance.

--该方法会移除所有online patch:

[oracle@dave db_1]$ cd hpatch/

[oracle@dave hpatch]$ pwd

/u01/app/oracle/product/11.2.0/db_1/hpatch

[oracle@dave hpatch]$ ls

bug13817131.pch  bug13817131.pchdave.fixup  bug13817131.so  orapatchdave.cfg

3.5 rollback patch

语法参考1.7 小节。

[oracle@dave db_1]$ opatch rollback -id 13817131 -connectString dave:sys:oracle

Invoking OPatch 11.2.0.1.7

Oracle 中间补丁程序安装程序版本11.2.0.1.7

版权所有 (c) 2011, Oracle Corporation。保留所有权利。

Oracle Home       : /u01/app/oracle/product/11.2.0/db_1

Central Inventory : /u01/app/oraInventory

  from           : /etc/oraInst.loc

OPatch version    : 11.2.0.1.7

OUI version       : 11.2.0.3.0

Log file location :/u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2012-10-09_19-32-31下午.log

RollbackSession 从OH '/u01/app/oracle/product/11.2.0/db_1' 回退中间补丁程序'13817131'

补丁程序只应在 '-all_nodes' 模式下应用/回退。

将 RAC 模式转换为'-all_nodes' 模式。

正在为组件 oracle.rdbms, 11.2.0.3.0 打补丁...

The patch will be removed from activedatabase instances.

正在数据库 'dave' 上禁用和删除联机补丁程序 'bug13817131.pch'

RollbackSession 从产品清单中删除中间补丁程序 '13817131'

Log file location:/u01/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2012-10-09_19-32-31下午.log

OPatch succeeded.

--alert log信息:

Tue Oct 09 19:32:41 2012

Patch bug13817131.pch Disabled - Update #5

Patch bug13817131.pch Removed - Update #6

Tue Oct 09 19:32:44 2012

Online patchbug13817131.pch has been disabled

Online patchbug13817131.pch has been removed

--查看PMON进程对内存的消耗:

[oracle@dave trace]$ pmap -d 2118|tail-20    

00007fb4ef239000     264 rwx-- 0000000000288000 008:00003libnnz11.so

00007fb4ef27b000      12 rwx-- 0000000000000000 000:00000   [ anon ]

00007fb4ef28c000       4 r-x-- 000000000c955000 008:00003oracle

00007fb4ef28d000       4rwxs- 0000000000000000 008:00003 hc_dave.dat

00007fb4ef28e000       8 rwx-- 0000000000000000 000:00000   [ anon ]

00007fb4ef290000     864 r-x-- 0000000000000000 008:00003libskgxp11.so

00007fb4ef368000    1024 ----- 00000000000d8000 008:00003libskgxp11.so

00007fb4ef468000       8 rwx-- 00000000000d8000 008:00003libskgxp11.so

00007fb4ef46a000     392 r-x-- 0000000000000000 008:00003libcell11.so

00007fb4ef4cc000    1024 ----- 0000000000062000 008:00003libcell11.so

00007fb4ef5cc000      40 rwx-- 0000000000062000 008:00003libcell11.so

00007fb4ef5d6000       8 rwx-- 0000000000000000 000:00000   [ anon ]

00007fb4ef5d8000       4 r-x-- 0000000000000000 008:00003libodmd11.so

00007fb4ef5d9000    1024 ----- 0000000000001000 008:00003libodmd11.so

00007fb4ef6d9000       4 rwx-- 0000000000001000 008:00003libodmd11.so

00007fb4ef6da000       4 rwx-- 0000000000000000 000:00000   [ anon ]

00007ffff0261000     132 rwx-- 0000000000000000 000:00000   [ stack ]

00007ffff03f6000       4 r-x-- 0000000000000000 000:00000   [ anon ]

ffffffffff600000       4 r-x-- 0000000000000000 000:00000   [ anon ]

mapped: 964344K    writeable/private: 8068K    shared: 720900K

这里我们使用oradebugdisable 和opatch rollback 都不会释放安装online patch 消耗的额外内存。当然重启实例之后,这些内存自会释放。

转自:https://blog.csdn.net/tianlesoftware/article/details/8214412

猜你喜欢

转载自blog.csdn.net/jolly10/article/details/81236847