RAC数据库上滚动(Rolling)安装/回退小补丁的方法
By JaneZhang(张建英) on 六月 15, 2012
在RAC数据库上安装小补丁时,为了不停止业务,可以使用滚动安装的方式(Rolling),也就是说,安装补丁的时候,先停止一个数据库实例,在这台节点安装这个补丁,然后启动这个实例,再停止下一个实例并安装这个补丁,这样能够保证一直有可用的数据库实例,业务能够继续。
使用滚动安装的前提是这个补丁是可以Rolling安装的,对于如何判断一个补丁是Rolling的,下面的文章中会提到。
一般来说,大体的Rolling安装的方式如下:
1. 下载补丁。
2. 打补丁之前,最好做一下数据库的备份。
3. 检查这次安装的补丁是否和以往的补丁冲突。
4. 如果有测试库,最好先在测试库测试一下这个补丁。
5. 务必仔细阅读补丁的Readme并按照其中的步骤来打补丁:
1). 用oracle用户将这个补丁上传到服务器上的一个目录.
2). 解压这个文件:
3). 停止1号机这个ORACLE_HOME下所有的数据库实例+ASM实例(如果有);
4). 在1号机打补丁:
$cd $ORACLE_HOME/OPatch/10082277
$opatch apply
5). 然后opatch会问您是否要打下一个节点,这时候执行下面的操作:
6). 启动1号机这个ORACLE_HOME下所有的数据库实例+ASM实例(如果有);
7). 停止2号机这个ORACLE_HOME下所有的数据库实例+ASM实例(如果有);
8). 在之前打补丁的那个提示符中,确认继续打下一个节点;
9). 启动2号机这个ORACLE_HOME下所有的数据库实例+ASM实例(如果有);
10).如果有多个节点,依次执行。
下面是在10.2.0.4 RAC上滚动(Rolling)安装补丁8575528的过程:
1).用oracle用户将这个补丁上传到服务器上的一个目录,比如:$ORACLE_HOME/OPatch下面.
$ pwd
/u01/app/oracle/OPatch
$ ls
docs emdpatch.pl jlib opatch opatch.ini opatch.pl opatchprereqs p8575528_10204_Linux-x86.zip
2).解压这个文件:
su - oracle
$ unzip p8575528_10204_Linux-x86.zip
Archive: p8575528_10204_Linux-x86.zip
creating: 8575528/
creating: 8575528/files/
creating: 8575528/files/lib/
creating: 8575528/files/lib/libserver10.a/
inflating: 8575528/files/lib/libserver10.a/kks1.o
inflating: 8575528/files/lib/libserver10.a/kksc.o
inflating: 8575528/files/lib/libserver10.a/kksh.o
inflating: 8575528/files/lib/libserver10.a/ksmp.o
creating: 8575528/etc/
creating: 8575528/etc/config/
inflating: 8575528/etc/config/inventory
inflating: 8575528/etc/config/actions
creating: 8575528/etc/xml/
inflating: 8575528/etc/xml/GenericActions.xml
inflating: 8575528/etc/xml/ShiphomeDirectoryStructu<wbr>re.xml<br> inflating: 8575528/README.txt<br> $ ls<br> 8575528 docs emdpatch.pl jlib opatch opatch.ini opatch.pl opatchprereqs p8575528_10204_Linux-x86.zip<br><br> 3).检查这个补丁是不是可以在RAC上滚动安装(rolling)。<br> $ $ORACLE_HOME/OPatch/opatch query -all /u01/app/oracle/OPatch/8575528|grep rolling<br> Patch is a rolling patch: <b>true <=====可以滚动安装</b><br><br> 4).停止1号机数据库的ORACLE_HOME下所有的数据库实例(如果有ASM,也要停止):<br> $srvctl stop instance -d <dbname> -i <instance_name><br> $srvctl stop asm -n <nodename><br><br> 比如:<br><br> $srvctl stop instance -d ONEPIECE -i ONEPIECE1<br> $srvctl stop asm -n nascds14<br> $ crs_stat -t<br> Name Type Target State Host<br> ------------------------------------------------------------<br> ora....E1.inst application OFFLINE OFFLINE<br> ora....SM1.asm application OFFLINE OFFLINE<br><br> 5). 在1号机打补丁:<br> 比如:<br> $su - oracle<br> $cd /u01/app/oracle/OPatch/<b>8575528</b><br><b>$opatch apply</b><br><br> Invoking OPatch 10.2.0.4.2<br><br> Oracle Interim Patch Installer version 10.2.0.4.2<br> Copyright (c) 2007, Oracle Corporation. All rights reserved.<br><br><br> Oracle Home : /u01/app/oracle<br> Central Inventory : /home/oracle/oraInventory<br> from : /etc/oraInst.loc<br> OPatch version : 10.2.0.4.2<br> OUI version : 10.2.0.4.0<br> OUI location : /u01/app/oracle/oui<br> Log file location : /u01/app/oracle/cfgtoollogs/opatch/opatch2012-06-13_01-27-38AM.log<br><br> ApplySession applying interim patch '8575528' to OH '/u01/app/oracle'<br><br> Running prerequisite checks...<br><br> OPatch detected the node list and the local node from the inventory. OPatch will patch the local system then<br><br> propagate the patch to the remote nodes.<br><br><br> This node is part of an Oracle Real Application Cluster.<br> Remote nodes: 'nascds15'<br> Local node: 'nascds14'<br> Please shutdown Oracle instances running out of this ORACLE_HOME on the local system.<br> (Oracle Home = '/u01/app/oracle')<br><br><br> Is the local system ready for patching? [y|n]<br> y <b><======输入y</b><br> User Responded with: Y<br> Backing up files and inventory (not for auto-rollback) for the Oracle Home<br> Backing up files affected by the patch '8575528' for restore. This might take a while...<br> Backing up files affected by the patch '8575528' for rollback. This might take a while...<br><br> Patching component oracle.rdbms, 10.2.0.4.0...<br> Updating archive file "/u01/app/oracle/lib/libserver10.a" with "lib/libserver10.a/kks1.o"<br> Updating archive file "/u01/app/oracle/lib/libserver10.a" with "lib/libserver10.a/kksc.o"<br> Updating archive file "/u01/app/oracle/lib/libserver10.a" with "lib/libserver10.a/kksh.o"<br> Updating archive file "/u01/app/oracle/lib/libserver10.a" with "lib/libserver10.a/ksmp.o"<br> Running make for target ioracle<br> ApplySession adding interim patch '8575528' to inventory<br><br> Verifying the update...<br> Inventory check OK: Patch ID 8575528 is registered in Oracle Home inventory with proper meta-data.<br> Files check OK: Files from Patch ID 8575528 are present in Oracle Home.<br><br> The local system has been patched. You can restart Oracle instances on it.<br><br><br> Patching in rolling mode.<br><br><br> The node 'nascds15' will be patched next.<br><br><br> Please shutdown Oracle instances running out of this ORACLE_HOME on 'nascds15'.<br> (Oracle Home = '/u01/app/oracle')<br><br> Is the node ready for patching? [y|n]<br><br> 6). 然后opatch会问您是否要打下一个节点。这时候执行下面的操作。<br><br> 7). 启动1号机的ASM 实例和数据库实例:<br> $srvctl start asm -n <nodename><br> $srvctl start instance -d <dbname> -i <instance_name><br><br> 比如:<br> $srvctl start asm -n nascds14<br> $srvctl start instance -d ONEPIECE -i ONEPIECE1<br><br> $crs_stat -t<br> ora....E1.inst application ONLINE ONLINE nascds14<br> ora....SM1.asm application ONLINE ONLINE nascds14<br><br> 8).停止2号机的ASM实例和数据库实例:<br> $srvctl stop instance -d <dbname> -i <instance_name><br> $srvctl stop asm -n <nodename><br><br> $srvctl stop instance -d ONEPIECE -i ONEPIECE2<br> $srvctl stop asm -n nascds15<br> $crs_stat<br> ora....E2.inst application OFFLINE OFFLINE<br> ora....SM2.asm application OFFLINE OFFLINE<br><br> 9). 在之前打补丁的那个提示符中,确认继续打下一个节点。<br> Is the node ready for patching? [y|n]<br> y <b><====输入y</b><br> User Responded with: Y<br> Updating nodes 'nascds15'<br> Apply-related files are:<br> FP = "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/copy_files.txt"<br> DP = "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/copy_dirs.txt"<br> MP = "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/make_cmds.txt"<br> RC = "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/remote_cmds.txt"<br><br> Instantiating the file "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/copy_files.txt.instantiated"<br><br> by replacing $ORACLE_HOME in "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/copy_files.txt" with<br><br> actual path.<br> Propagating files to remote nodes...<br> Instantiating the file "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/copy_dirs.txt.instantiated"<br><br> by replacing $ORACLE_HOME in "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/copy_dirs.txt" with<br><br> actual path.<br> Propagating directories to remote nodes...<br> Instantiating the file "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/make_cmds.txt.instantiated"<br><br> by replacing $ORACLE_HOME in "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/make_cmds.txt" with<br><br> actual path.<br> Running command on remote node 'nascds15':<br> cd /u01/app/oracle/rdbms/lib; /usr/bin/make -f ins_rdbms.mk ioracle ORACLE_HOME=/u01/app/oracle || echo<br><br> REMOTE_MAKE_FAILED::>&2<br><br><br> The node 'nascds15' has been patched. You can restart Oracle instances on it.<br><br> There were relinks on remote nodes. Remember to check the binary size and timestamp on the nodes 'nascds15' .<br> The following make commands were invoked on remote nodes:<br> 'cd /u01/app/oracle/rdbms/lib; /usr/bin/make -f ins_rdbms.mk ioracle ORACLE_HOME=/u01/app/oracle<br> '<br><br><br> OPatch succeeded.<br><br> 10). 启动2号机的ASM实例和数据库实例:<br> $srvctl start asm -n <nodename><br> $srvctl start instance -d <dbname> -i <instance_name><br><br> 比如:<br> $srvctl start asm -n nascds15<br> $srvctl start instance -d ONEPIECE -i ONEPIECE2<br><br> 11).在两个节点分别执行下面的命令来确认补丁已经安装成功。<br> $ORACLE_HOME/OPatch/opatch lsinventory<br><br> [oracle@nascds14 8575528]$ $ORACLE_HOME/OPatch/opatch lsinventory<br> Invoking OPatch 10.2.0.4.2<br><br> Oracle Interim Patch Installer version 10.2.0.4.2<br> Copyright (c) 2007, Oracle Corporation. All rights reserved.<br><br><br> Oracle Home : /u01/app/oracle<br> Central Inventory : /home/oracle/oraInventory<br> from : /etc/oraInst.loc<br> OPatch version : 10.2.0.4.2<br> OUI version : 10.2.0.4.0<br> OUI location : /u01/app/oracle/oui<br> Log file location : /u01/app/oracle/cfgtoollogs/opatch/opatch2012-06-13_01-44-11AM.log<br><br> Lsinventory Output file location : /u01/app/oracle/cfgtoollogs/opatch/lsinv/lsinventory2012-06-13_01-44-11AM.txt<br><br> --------------------------------------------------------------------------------<br> Installed Top-level Products (2):<br><br> Oracle Database 10g 10.2.0.1.0<br> Oracle Database 10g Release 2 Patch Set 3 10.2.0.4.0<br> There are 2 products installed in this Oracle Home.<br><br><br> Interim patches (1) :<br><br><b>Patch 8575528</b> : applied on Wed Jun 13 01:28:24 CST 2012<<<<<<<<<<<<<<<<<<<<br> Created on 17 Aug 2010, 07:56:36 hrs PST8PDT<br> Bugs fixed:<br> 8575528<br><br><br><br> Rac system comprising of multiple nodes<br> Local node = nascds14<br> Remote node = nascds15<br><br> --------------------------------------------------------------------------------<br><br> OPatch succeeded.<br> Rac system comprising of multiple nodes<br> Local node = nascds14<br> Remote node = nascds15<br><br> --------------------------------------------------------------------------------<br><br> OPatch succeeded.<br><br></wbr>
下面是在10.2.0.4 RAC上滚动(Rolling)回退补丁8575528的过程:
1).停止1号机数据库ORACLE_HOME下所有的数据库实例(如果有ASM,也要停止):
$srvctl stop instance -d <dbname> -i <instance_name>
$srvctl stop asm -n <nodename>
比如:
$srvctl stop instance -d ONEPIECE -i ONEPIECE1
$srvctl stop asm -n nascds14
$crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....E1.inst application OFFLINE OFFLINE
ora....SM1.asm application OFFLINE OFFLINE
2). 在1号机回滚补丁:
比如:
$su - oracle
$cd $ORACLE_HOME/OPatch/8575528
$opatch rollback -id 8575528
Invoking OPatch 10.2.0.4.2
Oracle Interim Patch Installer version 10.2.0.4.2
Copyright (c) 2007, Oracle Corporation. All rights reserved.
Oracle Home : /u01/app/oracle
Central Inventory : /home/oracle/oraInventory
from : /etc/oraInst.loc
OPatch version : 10.2.0.4.2
OUI version : 10.2.0.4.0
OUI location : /u01/app/oracle/oui
Log file location : /u01/app/oracle/cfgtoollogs/opatch/opatch2012-06-13_18-22-10PM.log
RollbackSession rolling back interim patch '8575528' from OH '/u01/app/oracle'
Running prerequisite checks...
OPatch detected the node list and the local node from the inventory. OPatch will patch the local system then
propagate the patch to the remote nodes.
This node is part of an Oracle Real Application Cluster.
Remote nodes: 'nascds15'
Local node: 'nascds14'
Please shut down Oracle instances running out of this ORACLE_HOME on all the nodes.
(Oracle Home = '/u01/app/oracle')
Are all the nodes ready for patching? [y|n]
y <=========输入y
User Responded with: Y
Backing up files affected by the patch '8575528' for restore. This might take a while...
Patching component oracle.rdbms, 10.2.0.4.0...
Updating archive file "/u01/app/oracle/lib/libserver10.a" with "lib/libserver10.a/kks1.o"
Updating archive file "/u01/app/oracle/lib/libserver10.a" with "lib/libserver10.a/kksc.o"
Updating archive file "/u01/app/oracle/lib/libserver10.a" with "lib/libserver10.a/kksh.o"
Updating archive file "/u01/app/oracle/lib/libserver10.a" with "lib/libserver10.a/ksmp.o"
Running make for target ioracle
RollbackSession removing interim patch '8575528' from inventory
Patching in rolling mode.
The node 'nascds15' will be patched next.
Please shutdown Oracle instances running out of this ORACLE_HOME on 'nascds15'.
(Oracle Home = '/u01/app/oracle')
Is the node ready for patching? [y|n]
3). 然后opatch会问您是否要在另外一个节点上回滚。这时候执行下面的操作。
4). 启动1号机ASM 实例和数据库实例:
$srvctl start asm -n <nodename>
$srvctl start instance -d <dbname> -i <instance_name>
比如:
$srvctl start asm -n nascds14
$srvctl start instance -d ONEPIECE -i ONEPIECE1
$crs_stat -t
ora....E1.inst application ONLINE ONLINE nascds14
ora....SM1.asm application ONLINE ONLINE nascds14
5).停止2号机的ASM实例和数据库实例:
$srvctl stop instance -d <dbname> -i <instance_name>
$srvctl stop asm -n <nodename>
$srvctl stop instance -d ONEPIECE -i ONEPIECE2
$srvctl stop asm -n nascds15
$crs_stat -t
ora....E2.inst application OFFLINE OFFLINE
ora....SM2.asm application OFFLINE OFFLINE
6). 在之前回滚补丁的那个提示符中,确认继续下一个节点。
The node 'nascds15' will be patched next.
Please shutdown Oracle instances running out of this ORACLE_HOME on 'nascds15'.
(Oracle Home = '/u01/app/oracle')
Is the node ready for patching? [y|n]
y <=========输入y
User Responded with: Y
Updating nodes 'nascds15'
Rollback-related files are:
FR = "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/remove_files.txt"
DR = "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/remove_dirs.txt"
FP = "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/copy_files.txt"
MP = "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/make_cmds.txt"
RC = "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/remote_cmds.txt"
Instantiating the file "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/remove_dirs.txt.instantiated"
by replacing $ORACLE_HOME in "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/remove_dirs.txt" with
actual path.
Removing directories on remote nodes...
Instantiating the file "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/copy_files.txt.instantiated"
by replacing $ORACLE_HOME in "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/copy_files.txt" with
actual path.
Propagating files to remote nodes...
Instantiating the file "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/copy_dirs.txt.instantiated"
by replacing $ORACLE_HOME in "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/copy_dirs.txt" with
actual path.
Propagating directories to remote nodes...
Instantiating the file "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/make_cmds.txt.instantiated"
by replacing $ORACLE_HOME in "/u01/app/oracle/.patch_storage/8575528_Aug_17_2010_07_56_36/rac/make_cmds.txt" with
actual path.
Running command on remote node 'nascds15':
cd /u01/app/oracle/rdbms/lib; /usr/bin/make -f ins_rdbms.mk ioracle ORACLE_HOME=/u01/app/oracle || echo
REMOTE_MAKE_FAILED::>&2
The node 'nascds15' has been patched. You can restart Oracle instances on it.
There were relinks on remote nodes. Remember to check the binary size and timestamp on the nodes 'nascds15' .
The following make commands were invoked on remote nodes:
'cd /u01/app/oracle/rdbms/lib; /usr/bin/make -f ins_rdbms.mk ioracle ORACLE_HOME=/u01/app/oracle
'
OPatch succeeded.
7). 启动2号机的ASM实例和数据库实例:
$srvctl start asm -n <nodename>
$srvctl start instance -d <dbname> -i <instance_name>
比如:
$srvctl start asm -n nascds15
$srvctl start instance -d ONEPIECE -i ONEPIECE2
8).在两个节点分别执行下面的命令来确认补丁已经回滚成功。
$ $ORACLE_HOME/OPatch/opatch lsinventory
Invoking OPatch 10.2.0.4.2
Oracle Interim Patch Installer version 10.2.0.4.2
Copyright (c) 2007, Oracle Corporation. All rights reserved.
Oracle Home : /u01/app/oracle
Central Inventory : /home/oracle/oraInventory
from : /etc/oraInst.loc
OPatch version : 10.2.0.4.2
OUI version : 10.2.0.4.0
OUI location : /u01/app/oracle/oui
Log file location : /u01/app/oracle/cfgtoollogs/opatch/opatch2012-06-13_19-40-41PM.log
Lsinventory Output file location : /u01/app/oracle/cfgtoollogs/opatch/lsinv/lsinventory2012-06-13_19-40-41PM.txt
--------------------------------------------------------------------------------
Installed Top-level Products (2):
Oracle Database 10g 10.2.0.1.0
Oracle Database 10g Release 2 Patch Set 3 10.2.0.4.0
There are 2 products installed in this Oracle Home.
There are no Interim patches installed in this Oracle Home.
Rac system comprising of multiple nodes
Local node = nascds14
Remote node = nascds15
--------------------------------------------------------------------------------
OPatch succeeded.