使用Out of Place升級策略進行Oracle Patch操作
資料庫升級、打補丁是我們經常面對的日常工作內容。在正常情況下,兩個因素是我們必須要考慮的問題:停機時間窗和回退方案。就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升級策略,很大程度上可以確保減少停機時間,原有配置保留和快速回退的要求。在實際場景下,對於升級要有全面的計劃和多種備選預案准備,防止出現潛在風險,威脅系統資料安全。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17203031/viewspace-2126643/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 11gR2 RAC out-of-place 滾動升級(2)
- 11gR2 RAC out-of-place 滾動升級(1)
- Starting AHF Services 使用root使用者進行升級操作
- ORACLE 11g 升級補丁(Patch)Oracle
- 對avalon的類名操作進行升級
- oracle小版本升級patch過程和分析Oracle
- 檢查oracle的patch的升級情況Oracle
- ORACLE EXADATA升級—從11.2.3.1.0到11.2.3.3.0–(7)升級Bundle Patch 23Oracle
- 【PATCH】Oracle12c升級補丁初體驗Oracle
- Oracle 12c 使用(Full Transportable Export/Import)進行升級/遷移OracleExportImport
- 使用web client對 vcenter 進行補丁升級Webclient
- 使用RPM包對RedHat進行核心升級(轉)Redhat
- 執行database replay進行升級測試Database
- flutter升級後 執行專案報錯 Warning: Podfile is out of dateFlutter
- oracle 補丁種類和升級方法以及oracle RAC Rolling Patch 說明Oracle
- suse 9 上oracle0204 升級0208__it may not be patchOracle
- ubuntu 6.10 升級策略(轉)Ubuntu
- 使用檔案複製的方式進行資料庫版本升級資料庫
- 生產庫升級:oracle 9.2.0.1升級oracle 9.2.0.8Oracle
- 如何使用diff 和 patch 命令對檔案進行協作?
- zt_oracle psu_cpu_bundle補丁patch升級upgrade相關概念Oracle
- 【Python Oracle】使用cx_Oracle 進行資料庫操作介紹PythonOracle資料庫
- oracle10g升級到oracle11g操作記錄Oracle
- MySQL5.6到5.7版本升級採用IN-PLACE的升級方式需要具體關注的地方MySql
- 使用組策略進行賬戶安全配置
- 修改組策略以安裝MSI程式進行許可權升級或許可權維持
- oracle 分割槽表進行shrink操作Oracle
- 以太坊智慧合約升級策略
- REST:使用PATCH進行部分更新 - mscharhagREST
- 探索Oracle之資料庫升級三 回退升級操作(11.2.0.4Downgrade 11.2.0.3)Oracle資料庫
- win10升級遮蔽工具怎麼使用_win10升級遮蔽工具如何操作Win10
- PSU的GI升級,ERROR: This patch is not applicable to GI home.ErrorAPP
- 樂橙進行全面品牌升級,打造更懂使用者的智慧家居
- JPA之使用JPQL進行CRUD操作
- win10通過映象檔案進行升級Win10
- AppBox升級進行時 - Attach陷阱(Entity Framework)APPFramework
- openssl版本升級操作記錄
- oracle升級步驟Oracle