阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

使用Out of Place升级策略进行Oracle Patch操作

211次阅读
没有评论

共计 11417 个字符,预计需要花费 29 分钟才能阅读完成。

数据库升级、打补丁是我们经常面对的日常工作内容。在正常情况下,两个因素是我们必须要考虑的问题:停机时间窗和回退方案。就 Oracle 而言,即便是最简单的更新操作,都难以做到“零停机”。回退方案是在一旦发现新版本存在问题,迅速的回退到原有的版本,支持应用访问。

目前,Oracle 推荐两种大规模升级的方法:In-Place 和 Out-of-Place。In Place 升级方法下,升级动作直接在原有的 Database Home 目录下。Out-of-Place 则是选择了一个新的 Oracle Database Home 目录。相对于 In place 策略,Out-of-Place 在空间上需要更多的消耗。

但是,Out-of-Place 的好处也是比较明显的,首先是可以比较方便的进行回退,同时在 Downtime 停机时间上,也有比较强的优势。

Out-of-Place 支持 Oracle 大版本和 Patch 两种操作方式,本文主要介绍使用 Out-Of-Place 方法打补丁 Patch 方法。

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

环境变量情况如下:

[oracle@testlife OPatch]$ env | grep ORA

ORACLE_SID=testdb

ORACLE_BASE=/u01/app/oracle

ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1

目标是在当前版本基础上,使用最新的 PSU 补丁文件。

2、补丁操作

升级 OPatch 工具。Oracle 默认自带的 OPatch 通常是不能满足补丁要求的,比较稳妥的手段是到 MOS 上下载最新的 OPatch 升级包,替代原有的程序。

[oracle@testlife upload]$ cp p6880880_112000_Linux-x86-64.zip $ORACLE_HOME

[oracle@testlife upload]$ cd $ORACLE_HOME

[oracle@testlife dbhome_1]$ mv OPatch OPatch_BAK

[oracle@testlife dbhome_1]$ unzip p6880880_112000_Linux-x86-64.zip 

Archive:  p6880880_112000_Linux-x86-64.zip

  creating: OPatch/

  inflating: OPatch/opatch.bat       

  inflating: OPatch/operr.bat       

(篇幅原因,有省略……)

[oracle@testlife dbhome_1]$ cd OPatch

[oracle@testlife OPatch]$ ./opatch lsinventory

Oracle Interim Patch Installer version 11.2.0.3.10

Copyright (c) 2016, 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

在升级过程中,会有两套 Oracle 环境变量切换的动作,为避免出现问题,可以设置两套 ORACLE_HOME 环境变量,根据不同的情况进行切换。

[oracle@testlife OPatch]$ cd ~

[oracle@testlife ~]$ export ORACLE_OWNER_GROUP=oracle:dba

[oracle@testlife ~]$ export ORACLE_BASE=$ORACLE_BASE

[oracle@testlife ~]$ export O_ORACLE_HOME=$ORACLE_HOME –Original Oracle Home

[oracle@testlife ~]$ export O_ORACLE_HOME_NAME=`grep OHOMENAME= $O_ORACLE_HOME/oui/bin/attachHome.sh | cut -f2 -d=`

[oracle@testlife ~]$ export C_ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1_clone –Clone Environment

[oracle@testlife ~]$ export C_ORACLE_HOME_NAME=clone

[oracle@testlife ~]$ env | grep ORA

C_ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1_clone

ORACLE_OWNER_GROUP=oracle:dba

ORACLE_SID=testdb

ORACLE_BASE=/u01/app/oracle

C_ORACLE_HOME_NAME=clone

O_ORACLE_HOME_NAME=OraDb11g_home1

ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1

O_ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1

下面,使用原有数据库克隆新的环境 Clone 数据库。

– 目录创建

[oracle@testlife ~]$ cd /

[oracle@testlife /]$ mkdir $C_ORACLE_HOME

[oracle@testlife /]$ chown $ORACLE_OWNER_GROUP $C_ORACLE_HOME

[oracle@testlife dbhome_1]$ pwd

/u01/app/oracle/product/11.2.0/dbhome_1

[oracle@testlife dbhome_1]$ ls -l | grep dbhome

[oracle@testlife dbhome_1]$ cd ..

[oracle@testlife 11.2.0]$ ls -l | grep dbhome

drwxr-xr-x. 75 oracle oinstall 4096 Oct 18 17:52 dbhome_1

drwxr-xr-x  2 oracle dba      4096 Oct 18 18:07 dbhome_1_clone

[oracle@testlife 11.2.0]$ cd $O_ORACLE_HOME

[oracle@testlife dbhome_1]$ tar cfp – . | (cd $C_ORACLE_HOME; tar xf –)

tar: ./bin/nmo: Cannot open: Permission denied

tar: ./bin/nmb: Cannot open: Permission denied

tar: ./bin/nmhs: Cannot open: Permission denied

tar: Exiting with failure status due to previous errors

[oracle@testlife dbhome_1]$

使用 clone.pl 脚本创建全新的 Clone 数据库。

[oracle@testlife dbhome_1]$ export ORACLE_HOME=$C_ORACLE_HOME –Clone 数据库目录

[oracle@testlife dbhome_1]$ perl $ORACLE_HOME/clone/bin/clone.pl \

> ORACLE_BASE=$ORACLE_BASE \

> ORACLE_HOME=$C_ORACLE_HOME \

> ORACLE_HOME_NAME=$C_ORACLE_HOME_NAME

./runInstaller -clone -waitForCompletion  “ORACLE_BASE=/u01/app/oracle” “ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1_clone” “ORACLE_HOME_NAME=clone” -silent -noConfig -nowait 

Starting Oracle Universal Installer…

Checking swap space: must be greater than 500 MB.  Actual 7967 MB    Passed

Preparing to launch Oracle Universal Installer from /tmp/OraInstall2016-10-18_06-13-35PM. Please wait …Oracle Universal Installer, Version 11.2.0.4.0 Production

Copyright (C) 1999, 2013, Oracle. All rights reserved.

You can find the log of this install session at:

 /u01/app/oraInventory/logs/cloneActions2016-10-18_06-13-35PM.log

………………………………………………………………………………………. 100% Done. 

Installation in progress (Tuesday, October 18, 2016 6:13:56 PM CST)

……………………………………………………………………                                                  78% Done.

Install successful

Linking in progress (Tuesday, October 18, 2016 6:14:00 PM CST)

Link successful

Setup in progress (Tuesday, October 18, 2016 6:14:35 PM CST)

Setup successful

End of install phases.(Tuesday, October 18, 2016 6:14:59 PM CST)

WARNING:

The following configuration scripts need to be executed as the “root” user.

/u01/app/oracle/product/11.2.0/dbhome_1_clone/root.sh

To execute the configuration scripts:

    1. Open a terminal window

    2. Log in as “root”

    3. Run the scripts

   

The cloning of clone was successful.

Please check ‘/u01/app/oraInventory/logs/cloneActions2016-10-18_06-13-35PM.log’ for more details.

切换到 root 进行脚本执行。

[root@testlife ~]# cd /u01/app/oracle/product/11.2.0/dbhome_1_clone

[root@testlife dbhome_1_clone]# ./root.sh

Check /u01/app/oracle/product/11.2.0/dbhome_1_clone/install/root_testlife.localdomain_2016-10-18_18-16-58.log for the output of root script

注意:此时 Clone 是一个和主库一样的程序包,主库在补丁过程中是支持对外操作的。

下面可以在 Clone 数据库上进行补丁操作。

[oracle@testlife upload]$ export ORACLE_HOME=$C_ORACLE_HOME

[oracle@testlife upload]$ cd 23615392/

[oracle@testlife 23615392]$ ls -l

total 32

drwxr-xr-x 13 oracle oinstall  4096 Jul 20 19:30 23054359

drwxr-xr-x  5 oracle oinstall  4096 Jul 20 19:30 23177551

-rw-r–r–  1 oracle oinstall 18806 Jul 20 19:50 README.html

-rw-r–r–  1 oracle oinstall    25 Jul 20 19:30 README.txt

[oracle@testlife 23615392]$ cd 23054359/

[oracle@testlife 23054359]$ $ORACLE_HOME/OPatch/opatch apply

Oracle Interim Patch Installer version 11.2.0.3.10

Copyright (c) 2016, Oracle Corporation.  All rights reserved.

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

Central Inventory : /u01/app/oraInventory

  from          : /u01/app/oracle/product/11.2.0/dbhome_1_clone/oraInst.loc

OPatch version    : 11.2.0.3.10

OUI version      : 11.2.0.4.0

(中间略 …)

两个补丁均完成。暂停原有服务,进行目录切换。

[oracle@testlife 23177551]$ export ORACLE_HOME=$O_ORACLE_HOME

[oracle@testlife 23177551]$ env | grep ORACLE_SID

ORACLE_SID=testdb

[oracle@testlife 23177551]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Tue Oct 18 19:33:52 2016

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> exit

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

[oracle@testlife 23177551]$ $ORACLE_HOME/bin/lsnrctl stop

LSNRCTL for Linux: Version 11.2.0.4.0 – Production on 18-OCT-2016 19:34:32

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (ADDRESS=(PROTOCOL=tcp)(HOST=)(PORT=1521))

The command completed successfully

将原有数据库目录 Detach。

[oracle@testlife 23177551]$ cd ~

[oracle@testlife ~]$ export ORACLE_HOME=$O_ORACLE_HOME

[oracle@testlife ~]$ cd $ORACLE_HOME/..

[oracle@testlife 11.2.0]$ $ORACLE_HOME/oui/bin/detachHome.sh

Starting Oracle Universal Installer…

Checking swap space: must be greater than 500 MB.  Actual 7967 MB    Passed

The inventory pointer is located at /etc/oraInst.loc

The inventory is located at /u01/app/oraInventory

‘DetachHome’ was successful.

– 原有目录修改名称

[oracle@testlife 11.2.0]$ mv $ORACLE_HOME `echo $ORACLE_HOME`_to_be_removed

[oracle@testlife 11.2.0]$ ls -l

total 8

drwxr-xr-x  79 oracle dba      4096 Oct 18 19:31 dbhome_1_clone

drwxr-xr-x. 75 oracle oinstall 4096 Oct 18 17:52 dbhome_1_to_be_removed

Detach 新的目录对象。

[oracle@testlife 11.2.0]$ export ORACLE_HOME=$C_ORACLE_HOME

[oracle@testlife 11.2.0]$ $ORACLE_HOME/oui/bin/detachHome.sh

Starting Oracle Universal Installer…

Checking swap space: must be greater than 500 MB.  Actual 7967 MB    Passed

The inventory pointer is located at /etc/oraInst.loc

The inventory is located at /u01/app/oraInventory

‘DetachHome’ was successful.

–Clone 出新的文件目录。

[oracle@testlife 11.2.0]$ mv $C_ORACLE_HOME $O_ORACLE_HOME

[oracle@testlife 11.2.0]$ export ORACLE_HOME=$O_ORACLE_HOME

[oracle@testlife 11.2.0]$ perl $ORACLE_HOME/clone/bin/clone.pl \

> ORACLE_BASE=$ORACLE_BASE \

> ORACLE_HOME=$O_ORACLE_HOME \

> ORACLE_HOME_NAME=$O_ORACLE_HOME_NAME

./runInstaller -clone -waitForCompletion  “ORACLE_BASE=/u01/app/oracle” “ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1” “ORACLE_HOME_NAME=OraDb11g_home1” -silent -noConfig -nowait 

Starting Oracle Universal Installer…

Checking swap space: must be greater than 500 MB.  Actual 7967 MB    Passed

Preparing to launch Oracle Universal Installer from /tmp/OraInstall2016-10-18_07-39-36PM. Please wait …Oracle Universal Installer, Version 11.2.0.4.0 Production

Copyright (C) 1999, 2013, Oracle. All rights reserved.

You can find the log of this install session at:

 /u01/app/oraInventory/logs/cloneActions2016-10-18_07-39-36PM.log

………………………………………………………………………………………. 100% Done.

(篇幅原因,有省略……)

The cloning of OraDb11g_home1 was successful.

Please check ‘/u01/app/oraInventory/logs/cloneActions2016-10-18_07-39-36PM.log’ for more details.

(执行脚本略……)

启动原有数据库,此时已经是更新过的目录了。

[oracle@testlife 11.2.0]$  export ORACLE_HOME=$O_ORACLE_HOME

[oracle@testlife 11.2.0]$ env | grep ORACLE_SID

ORACLE_SID=testdb

[oracle@testlife 11.2.0]$ $ORACLE_HOME/bin/lsnrctl start LISTENER

LSNRCTL for Linux: Version 11.2.0.4.0 – Production on 18-OCT-2016 19:44:23

The listener supports no services

The command completed successfully

[oracle@testlife 11.2.0]$ $ORACLE_HOME/bin/sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Tue Oct 18 19:44:45 2016

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup

ORACLE instance started.

Total System Global Area 3540881408 bytes

Fixed Size                  2258320 bytes

Variable Size            855640688 bytes

Database Buffers        2667577344 bytes

Redo Buffers              15405056 bytes

Database mounted.

Database opened.

注意:此时可以完成各个升级补丁需要进行的 postinstall 操作,更新数据库或者重新编译数据库对象。

[oracle@testlife 11.2.0]$ cd $ORACLE_HOME/rdbms/admin

[oracle@testlife admin]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Tue Oct 18 19:46:45 2016

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

SQL> conn / as sysdba

Connected.

SQL> @catbundle.sql psu apply

后续将新创建设置的环境变量重置,重新启动服务器。

[oracle@testlife admin]$ exit

logout

[root@testlife ~]# su – oracle

[oracle@testlife ~]$ env | grep ORA

ORACLE_SID=testdb

ORACLE_BASE=/u01/app/oracle

ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1

[oracle@testlife ~]$ sqlplus /nolog

SQL*Plus: Release 11.2.0.4.0 Production on Tue Oct 18 20:01:08 2016

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

SQL> conn / as sysdba

Connected.

SQL> startup force

ORACLE instance started.

Total System Global Area 3540881408 bytes

Fixed Size                  2258320 bytes

Variable Size            855640688 bytes

Database Buffers        2667577344 bytes

Redo Buffers              15405056 bytes

Database mounted.

Database opened.

– 升级完成

SQL> select version, comments from dba_registry_history;

VERSION                        COMMENTS

—————————— —————————–

11.2.0.4                      Patchset 11.2.0.2.0

11.2.0.4                      Patchset 11.2.0.2.0

11.2.0.4.160719OJVMPSU        RAN jvmpsu.sql

11.2.0.4                      PSU 11.2.0.4.160719

11.2.0.4.160719OJVMPSU        OJVM PSU post-install

                              Patch 23177551 applied

6 rows selected

最后,运行一段时间之后,确认升级版本没有问题,就可以将原有的目录删除掉。

[oracle@testlife trace]$ cd ~

[oracle@testlife ~]$ rm -rf `echo $ORACLE_HOME`_to_be_removed

[oracle@testlife ~]$ cd $ORACLE_HOME

[oracle@testlife dbhome_1]$ cd ..

[oracle@testlife 11.2.0]$ ls -l

total 4

drwxr-xr-x 79 oracle dba 4096 Oct 18 19:39 dbhome_1

3、结论

Out of Place 升级策略,很大程度上可以确保减少停机时间,原有配置保留和快速回退的要求。在实际场景下,对于升级要有全面的计划和多种备选预案准备,防止出现潜在风险,威胁系统数据安全。

更多 Oracle 相关信息见 Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-10/136213.htm

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-22发表,共计11417字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中