使用OPatch给Oracle打补丁
本篇主要介绍一下如何在11g下面使用OPatch进行PSU升级。
1、 环境介绍
我们选择11gR2作为实验环境。
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_HOME下,是自带一个OPatch工具包的。一般小版本的升级,都是通过OPatch来完成。
[oracle@mytest ~]$ cd $ORACLE_HOME
[oracle@mytest db]$ ls
apex config dc_ocm has javavm log odbc oui rdbms sqlj uix
assistants crs deinstall hs jdbc md olap owb Readme.txt sqlplus usm
bin csmig demo ide jdev mesg OPatch owm relnotes srvm utl
ccr css diagnostics install jdk mgw opmn perl root.sh suptools wwg
cdata ctx dv instantclient jlib network oracore plsql scheduler sysman xdk
cfgtoollogs cv emcli inventory ldap nls oraInst.loc precomp slax timingframework
clone dbs EMStage j2ee lib oc4j ord racg sqldeveloper ucp
不过,同Oracle自带的Uninstall一样,11.2.0.1自带的OPatch的版本是不能提供升级功能的。所以,我们通常需要首先升级OPatch,之后才能进行打补丁。
2、OPatch升级
首先,我们需要确定当前的OPatch版本。进入OPatch目录之后,可以通过版本首先确认。
[oracle@mytest db]$ ls -ltr OPatch/
total 108
-rw-r-----. 1 oracle oinstall 2576 May 6 2009 opatch.pl
-rw-r-----. 1 oracle oinstall 23695 Aug 2 2010 emdpatch.pl
-rwx--x---. 1 oracle oinstall 9352 Mar 31 2011 opatchdiag.bat
-rwx--x---. 1 oracle oinstall 10056 Mar 31 2011 opatchdiag
-rwx--x---. 1 oracle oinstall 19867 May 28 2013 opatch.bat
-rwx--x---. 1 oracle oinstall 31493 May 28 2013 opatch
drwxr-xr-x. 5 oracle oinstall 58 Apr 24 11:06 ocm
drwxr-xr-x. 4 oracle oinstall 62 Apr 24 11:06 opatchprereqs
drwxr-xr-x. 2 oracle oinstall 88 Apr 24 11:06 docs
drwxr-xr-x. 3 oracle oinstall 202 Apr 24 11:06 jlib
drwxr-xr-x. 3 oracle oinstall 68 Apr 24 11:06 oplan
drwxr-xr-x. 3 oracle oinstall 124 Apr 24 11:06 crs
-rw-r-----. 1 oracle oinstall 49 Apr 24 11:06 opatch.ini
[oracle@mytest OPatch]$ ./opatch version
OPatch Version: 11.2.0.3.4
OPatch succeeded.
11.2.0.1自带的OPatch版本为11.1.0.6.6,我们需要首先升级OPatch。第一步是进行原有OPatch备份。
[oracle@mytest db]$ tar zcvf opatch_bk.tar OPatch
OPatch/
OPatch/opatchprereqs/
OPatch/opatchprereqs/prerequisite.properties
(篇幅原因,省略部分内容)
OPatch/jlib/opatchprereq.jar
OPatch/opatch
OPatch/opatch.ini
最新版本的OPatch可以从MOS上面下载到,补丁文件名称为:p6880880_112000_Linux-x86-64_25.zip。
[oracle@mytest softwares]$ ls -ltr p688*
-rw-r--r--. 1 oracle oinstall 120388005 Apr 24 18:52 p6880880_112000_Linux-x86-64_25.zip
--解压到ORACLE_HOME目录上
[oracle@mytest softwares]$ unzip p6880880_112000_Linux-x86-64_25.zip -d $ORACLE_HOME
Archive: p6880880_112000_LINUX.zip
creating: /u01/app/oracle/OPatch/oplan/
(篇幅原因,省略部分……)
inflating: /u01/app/oracle/product/11.2.0/db/OPatch/auto/dbsessioninfo/README.txt
inflating: /u01/app/oracle/product/11.2.0/db/OPatch/opatch_env.sh
inflating: /u01/app/oracle/product/11.2.0/db/OPatch/operr
之后,验证OPatch安装成功。
[oracle@mytest OPatch]$ ./opatch version
OPatch Version: 11.2.0.3.25
OPatch succeeded.
3、补丁安装
如果OPatch不是最新的版本,直接安装PSU可能会有各种的问题。更新OPatch之后,我们就可以下载对应的PSU进行更新。
[oracle@mytest softwares]$ ls -ltr p29913194_112040_Linux-x86-64-DB-191015.zip
-rw-r--r--. 1 oracle oinstall 284969236 Apr 25 07:58 p29913194_112040_Linux-x86-64-DB-191015.zip
[oracle@mytest softwares]$ unzip p29913194_112040_Linux-x86-64-DB-191015.zip -d $ORACLE_HOME
(省略)
[oracle@bsplinux oracle]$ cd 12419378/
[oracle@bsplinux 12419378]$ ls -l
total 60
drwxr-xr-x 3 oracle oinstall 4096 Jul 8 2011 custom
drwxr-xr-x 4 oracle oinstall 4096 Jul 8 2011 etc
drwxr-xr-x 12 oracle oinstall 4096 Jul 8 2011 files
-rwxr-xr-x 1 oracle oinstall 2871 Jul 8 2011 patchmd.xml
-rw-rw-r-- 1 oracle oinstall 40790 Jul 18 2011 README.html
-rw-r--r-- 1 oracle oinstall 21 Jul 8 2011 README.txt
将数据库和监听程序关闭。
[oacle@mytest ~]$ !sql
sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.4.0 Production on һ 45 08:08:13 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
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
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@mytest ~]$ lsnrctl stop
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 25-42022 08:54:22
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=mytest)(PORT=1521)))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
Linux Error: 111: Connection refused
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
TNS-12541: TNS:no listener
TNS-12560: TNS:protocol adapter error
TNS-00511: No listener
Linux Error: 111: Connection refused
进入安装目录,使用OPatch进行更新。
[oracle@mytest softwares]$ cd $ORACLE_HOME
[oracle@mytest db]$ cd 29913194
[oracle@bsplinux 12419378]$ $ORACLE_HOME/OPatch/opatch apply
/bin/ld: warning: -z lazyload ignored.
/bin/ld: warning: -z nolazyload ignored.
/bin/ld: warning: -z lazyload ignored.
/bin/ld: warning: -z nolazyload ignored.
/bin/ld: warning: -z lazyload ignored.
/bin/ld: warning: -z nolazyload ignored.
/bin/ld: warning: -z lazyload ignored.
/bin/ld: warning: -z nolazyload ignored.
/bin/ld: warning: -z lazyload ignored.
/bin/ld: warning: -z nolazyload ignored.
/bin/ld: warning: -z lazyload ignored.
/bin/ld: warning: -z nolazyload ignored.
/bin/ld: warning: -z lazyload ignored.
/bin/ld: warning: -z nolazyload ignored.
/bin/ld: warning: -z lazyload ignored.
/bin/ld: warning: -z nolazyload ignored.
/bin/ld: warning: -z lazyload ignored.
/bin/ld: warning: -z nolazyload ignored.
Composite patch 29913194 successfully applied.
OPatch Session completed with warnings.
Log file location: /u01/app/oracle/product/11.2.0/db/cfgtoollogs/opatch/opatch2022-04-25_08-57-56AM_1.log
OPatch completed with warnings.
启动数据库,确定更新成功。
[oracle@mytest ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.4.0 Production on һ 45 09:04:01 2022
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to an idle instance.
SQL> startup;
ORACLE instance started.
Total System Global Area 826753024 bytes
Fixed Size 2257760 bytes
Variable Size 486542496 bytes
Database Buffers 331350016 bytes
Redo Buffers 6602752 bytes
Database mounted.
Database opened.
SQL> @?/rdbms/admin/catbundle.sql psu apply
PL/SQL procedure successfully completed.
4、确定补丁成功
最后我们需要确定补丁安装成功。对小补丁的升级来说,我们是不能够v$version视图中看到的。
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
5 rows selected.
通过OPatch的信息库记录,可以看到补丁信息。
Interim patches (1) :
Patch 29913194 : applied on Mon Apr 25 08:59:51 CST 2022
Unique Patch ID: 23112673
Patch description: "Database Patch Set Update : 11.2.0.4.191015 (29913194)"
Created on 12 Sep 2019, 21:00:41 hrs PST8PDT
Sub-patch 29497421; "Database Patch Set Update : 11.2.0.4.190716 (29497421)"
Sub-patch 29141056; "Database Patch Set Update : 11.2.0.4.190416 (29141056)"
Sub-patch 28729262; "Database Patch Set Update : 11.2.0.4.190115 (28729262)"
Sub-patch 28204707; "Database Patch Set Update : 11.2.0.4.181016 (28204707)"
Sub-patch 27734982; "Database Patch Set Update : 11.2.0.4.180717 (27734982)"
Sub-patch 27338049; "Database Patch Set Update : 11.2.0.4.180417 (27338049)"
Sub-patch 26925576; "Database Patch Set Update : 11.2.0.4.180116 (26925576)"
Sub-patch 26392168; "Database Patch Set Update : 11.2.0.4.171017 (26392168)"
Sub-patch 26609445; "Database Patch Set Update : 11.2.0.4.170814 (26609445)"
Sub-patch 25869727; "Database Patch Set Update : 11.2.0.4.170718 (25869727)"
Sub-patch 24732075; "Database Patch Set Update : 11.2.0.4.170418 (24732075)"
Sub-patch 24006111; "Database Patch Set Update : 11.2.0.4.161018 (24006111)"
Sub-patch 23054359; "Database Patch Set Update : 11.2.0.4.160719 (23054359)"
Sub-patch 22502456; "Database Patch Set Update : 11.2.0.4.160419 (22502456)"
Sub-patch 21948347; "Database Patch Set Update : 11.2.0.4.160119 (21948347)"
Sub-patch 21352635; "Database Patch Set Update : 11.2.0.4.8 (21352635)"
Sub-patch 20760982; "Database Patch Set Update : 11.2.0.4.7 (20760982)"
Sub-patch 20299013; "Database Patch Set Update : 11.2.0.4.6 (20299013)"
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)"
Sub-patch 18522509; "Database Patch Set Update : 11.2.0.4.3 (18522509)"
Sub-patch 18031668; "Database Patch Set Update : 11.2.0.4.2 (18031668)"
Sub-patch 17478514; "Database Patch Set Update : 11.2.0.4.1 (17478514)"
Bugs fixed:
22195448, 18619917, 19309466, 24570598, 28876684, 21172913, 17655240
18384391, 16992075, 28855981, 18189036, 19781326, 13609098, 16285691
16756406, 22195441, 17025461, 18430495, 17323222, 16472716, 19289642
29483723, 21502702, 19915271, 14458214, 19516448, 23713236, 22195457
23140259, 20475845, 22148226, 22502493, 26030218, 18331850, 17945983
18272672, 13498382, 16410570, 24652769, 16494615, 19174430, 21352646
16901385, 16596890, 22243719, 18673304, 17610798, 19891090, 25369547
18456514, 8322815, 18996843, 22657942, 21387964, 17313525, 20334344
17050888, 17174582, 18317531, 17495022, 11733603, 22250006, 17798953
19285025, 18260550, 14015842, 18031668, 17390160, 18316692, 19458377
14368995, 17551063, 16832076, 21343838, 16065166, 12905058, 14735792
28612674, 16855292, 16579084, 25427662, 23315889, 21179898, 11786053
15990359, 13364795, 17982832, 18235390, 18293054, 18685892, 18673325
19393542, 20142975, 14657740, 24835538, 17393683, 17389192, 16315398
20861693, 17783588, 17852463, 17037130, 19358317, 17441661, 17284817
14034426, 28254374, 20631274, 19207117, 17891946, 17279227, 17588480
17291347, 26569225, 16731148, 17518652, 24662775, 21097043, 19475971
24528741, 22321741, 17165204, 26245237, 17891943, 17359610, 18282562
17265217, 17465741, 22551446, 18191164, 16721594, 18614015, 27825893
18440095, 17348614, 19827973, 19769489, 20596234, 17346671, 18482502
16043574, 17360606, 22321756, 19211724, 17392698, 19463893, 29033139
17477958, 17040764, 18362222, 19463897, 24476274, 22296366, 24624166
17853456, 13853126, 18273830, 17570606, 14521849, 17816865, 13558557
26007010, 19692824, 16685417, 21868720, 17951233, 25505407, 18180390
17040527, 14692762, 17027426, 24476265, 24975421, 23177648, 17851160
19888853, 16870214, 18009564, 18202441, 20882568, 20803583, 23026585
18604692, 17227073, 17622427, 20657411, 16903536, 19006849, 20506699
17865671, 28000269, 17883081, 16228604, 23536835, 17761775, 16306373
17325413, 17082359, 12747740, 22168163, 16091637, 20569094, 19680952
16850630, 17694209, 17468141, 26667015, 17877323, 18230522, 24563422
17446237, 19469538, 17889549, 17551674, 16233738, 20598042, 29633753
22730454, 16042673, 17437634, 17571039, 19049453, 26667023, 19972570
18849970, 21532755, 20860659, 22905130, 21168487, 17016369, 20387265
17231779, 16833527, 21343775, 17297939, 16069901, 21343897, 27710072
18522509, 14285317, 17484731, 21972320, 22380919, 19972569, 18436647
19972568, 17716305, 23065323, 21059919, 19972566, 19972564, 21983325
26667032, 17394950, 17853498, 24790914, 23571055, 20657441, 16542886
17551699, 21286665, 17006570, 17365043, 17752995, 25914276, 17296856
18051556, 12364061, 18029658, 17546973, 18262334, 18783224, 19699191
22353199, 17227277, 28305362, 18018515, 16180763, 16943711, 17982555
23294548, 20828947, 18098207, 26679352, 13960236, 18436307, 19584068
16898135, 13936038, 19601762, 25423453, 18339044, 17282229, 14054676
25505394, 25600421, 18228645, 19013183, 18856999, 25042823, 17721717
17239687, 18259031, 25248384, 28806384, 25634317, 21354456, 20134113
23725036, 20273319, 18471685, 28501075, 30237239, 17258090, 21063322
16344544, 17344412, 17903598, 17011832, 18135678, 18704244, 22507210
17786518, 19718981, 25655390, 17242746, 16354467, 21795111, 19197175
17390431, 17835627, 17672719, 17393915, 25505371, 16777840, 25879984
21566639, 17811456, 18765602, 19730508, 17385178, 18166013, 17484762
10136473, 6599380, 20717359, 20296213, 21425496, 27097854, 26544823
13955826, 18193833, 17545847, 16837842, 18682983, 18964939, 19871910
25505382, 17811447, 18554763, 25165496, 21132297, 25957038, 20004087
17889583, 12816846, 19544839, 26631046, 22507234, 18774543, 24719736
18868646, 18747196, 17042658, 20627866, 17824637, 19429927, 21429602
14106803, 16524926, 13951456, 17343514, 18139690, 18277454, 19271443
17019345, 18681862, 17186905, 25823754, 23330119, 17811438, 26474853
18554871, 20169408, 17215560, 16875449, 24908321, 17274537, 17602269
21380789, 26575788, 17184721, 19032867, 17762296, 14829250, 18508861
19466309, 16929165, 14602788, 23330124, 17811429, 28849751, 17019356
25654936, 18899974, 18441944, 17811789, 17754782, 17752121, 22809871
20074391, 14852021, 17705023, 13645875, 17201159, 24316947, 18308268
16668584, 19777862, 17786278, 25947799, 16198143, 29027694, 18828868
17586955, 28076295, 20879889, 22977256, 16692232, 19578350, 28022101
22594718, 27374796, 21142837, 20869721, 17649265, 16384983, 26439748
25879656, 21756699, 19697993, 17957017, 19121551, 17570240, 28364007
17787259, 19788842, 18382302, 27086138, 23007241, 21330264, 27351628
18094246, 21197626, 14338435, 13944971, 21656630, 20031873, 17375354
18886413, 21698350, 17156148, 17936109, 20509482, 21538567, 27255377
24717859, 22683212, 18762750, 21526048, 24560906, 16450169, 17478145
18096714, 17238511, 26078387, 27053456, 20144308, 17311728, 17648596
18244962, 19433930, 17308789, 22836801, 21756677, 20476175, 19297917
18674047, 14084247, 22683225, 19788303, 21174504, 18280813, 28819280
27534509, 17614227, 28357401, 16833845, 18948177, 17006183, 18092127
19727057, 17205719, 21756661, 20004021, 17922254, 17695685, 13837378
26039623, 18084625, 17912217, 11883252, 24842886, 12982566, 14176370
14764829, 20856766, 21847223, 15861775, 17258582, 16875230, 21668627
19487147, 17237521, 29511611, 25635149, 16934803, 20925795, 17848897
20441797, 28100487, 26482376, 19554106, 21629064, 18199537, 16613964
18334586, 17288409, 17341326, 18091059, 17449815, 17299889, 15913355
16399083, 21538485, 18740837, 20294666, 17546761, 14565184, 25775213
21517440, 18155762, 17614134, 16956380, 19854503, 14245531, 16194160
18325460, 15979965, 19207156, 20671094, 14705949, 27870645, 23105538
26198926, 25093656, 19258504, 18247991, 16314254, 16912439, 17246576
17655634, 20067212, 24433711, 19930276, 19721304, 22092979, 19490948
18203835, 20506715, 18203838, 18973907, 18203837, 29483672, 19615136
17587063, 18000422, 23003979, 20506706, 18641451, 18090142, 21641760
17019086, 13871092, 19272701, 17397545, 16785708, 19373893, 19461270
18373438, 21051862, 18641461, 17346091, 13829543, 16220077, 17008068
18061914, 21422580, 20448824, 22351572, 18674024, 30275359, 19689979
18604493, 24411921, 23008056, 30275351, 17596908, 22901797, 17036973
18610915, 17612828, 20725343, 28199085, 23194294, 17892268, 21051858
17630484, 21051852, 17767676, 17232014, 17501491, 22893153, 12611721
25555252, 14354737, 18356166, 17071721, 17835048, 25764020, 16863422
21787056, 22195485, 22782647, 21051840, 17267114, 18043064, 17082983
21538558, 26243698, 20324049, 18641419, 16392068, 18744139, 24348685
26746894, 16618694, 14133975, 22195492, 18331812, 27072923, 18093615
14010183, 16595641, 17080436, 17332800, 20777150, 25897615, 21453153
20299015, 18413820, 20513399, 21281607, 18264060, 13866822, 16819962
22465352, 21351877, 21051833, 18673342, 17600719, 18841764, 17842825
20558005, 17088068, 29200700, 27441326, 9756271, 22195465, 18440047
16571443, 19211433, 18328509, 20331945, 27567477, 18384537, 18607546
18674465, 16422541, 18306996, 17254374, 18315328, 23115139, 17443671
28790634, 17478514, 21067387, 16268425, 16360112, 17381384, 22195477
17726838, 18723434, 17235750, 18510194, 17571306, 17302277, 21842740
17551709, 26910644, 17634921, 25489607, 23328639, 16538760
--------------------------------------------------------------------------------
OPatch succeeded.
在dba_registry_history中,我们也可以看到记录。
SQL> select version, id, bundle_series, comments from dba_registry_history;
VERSION ID BUNDLE_SERIES
------------------------------ ---------- ------------------------------
COMMENTS
--------------------------------------------------------------------------------
11.2.0.4 0 PSU
Patchset 11.2.0.2.0
11.2.0.4 191015 PSU
PSU 11.2.0.4.191015
2 rows selected.
5、结论
打补丁、升级数据库是DBA的基本功之一。本文主要介绍了OPatch进行的最简单的补丁升级,权当记录之用。