目录
1.备库备份oracle_home目录
2.备库关闭数据库服务及监听程序
3.备库升级Opatch
4.备库应用33806152补丁
5.备库应用33808367补丁
6.主库备份 oracle_home目录、上传补丁包
7.主库关闭数据库及监听程序
8.主库升级Opatch
9.编译无效对象
10.检查主库的补丁注册情况
11.备库切换主库完成补丁注册
1.备库备份oracle_home目录
备份oracle_home目录的主要目地是为了一旦补丁应用失败可以立即进行回滚。
[oracle@test2 ~]$ du -sh $ORACLE_HOME
9.6G /u01/app/oracle/product/19.0.0/db_1
##进入oraclehome目录
[oracle@test2 ~]$ cd $ORACLE_HOME/
[oracle@test2 db_1]$ cd ..
[oracle@test2 19.0.0]$ ls
db_1
##压缩db_1目录的内容完成oracle数据库软件备份
[oracle@test2 19.0.0]$ tar -cvzf db_home.tar.g db_1/
......
[oracle@test2 19.0.0]$ ls
db_1 db_home.tar.g
##查看压缩后的目录
[oracle@test2 19.0.0]$ du -sh db_home.tar.g
4.1G db_home.tar.g
2.备库关闭数据库服务及监听程序
注意:如果主备在生产期间需要停止备库的同步服务
##关闭数据库
sqlplus / as sysdba
shu immediate
exit
##关闭监听
lsnrctl stop
3.备库升级Opatch
##删除当前Opatch目录
rm -rf OPatch/
##进入存放Opatch压缩目录解压OPatch到ORACLE_HOME目录
cd /u01/app/patch/
ls
p33806152_190000_Linux-x86-64.zip p33808367_190000_Linux-x86-64.zip p6880880_190000_Linux-x86-64.zip
unzip -d $ORACLE_HOME p6880880_190000_Linux-x86-64.zip
##查看OPatch版本
/u01/app/oracle/product/19.0.0/db_1/OPatch/opatch version
OPatch Version: 12.2.0.1.30
OPatch succeeded.
4.备库应用33806152补丁
#解压补丁
cd /u01/app/patch/
ls
p33806152_190000_Linux-x86-64.zip p33808367_190000_Linux-x86-64.zip p6880880_190000_Linux-x86-64.zip
[oracle@test2 patch]$ unzip p33806152_190000_Linux-x86-64.zip
Archive: p33806152_190000_Linux-x86-64.zip
creating: 33806152/
......
[oracle@test2 patch]$ cd 33806152/
[oracle@test233806152]$ ls
custom etc files README.html README.txt
[oracle@test2 33806152]$ $ORACLE_HOME/OPatch/opatch prereq -help
##检查补丁是否冲突
[oracle@test2 33806152]$ $ORACLE_HOME/OPatch/opatch prereq CheckConflictAgainstOHWithDetail
Prereq "checkConflictAgainstOHWithDetail" passed.
##应用补丁
[oracle@test2 33806152]$ $ORACLE_HOME/OPatch/opatch apply
##输入y
是否继续? [y|n]
y
User Responded with: Y
All checks passed.
请关闭本地系统上在此 ORACLE_HOME 之外运行的 Oracle 实例。
(Oracle 主目录 = '/u01/app/oracle/product/19.0.0/db_1')
##输入y
本地系统是否已准备打补丁? [y|n]
y
User Responded with: Y
.....
OPatch succeeded.
##检查补丁应用情况
[oracle@test2 33806152]$ $ORACLE_HOME/OPatch/opatch lsinv
Patch 33806152 : applied on Mon Jul 18 16:03:49 CST 2022
Unique Patch ID: 24713297
Patch description: "Database Release Update : 19.15.0.0.220419 (33806152)"
Created on 4 Apr 2022, 06:06:27 hrs UTC
Bugs fixed:
1297945, 7391838, 8460502, 8476681, 14570574, 14735102, 15931756
......
OPatch succeeded.
5.备库应用33808367补丁
备库应用补丁后不进行注册,待备库切换至主库自动注册。
##解压补丁
[oracle@test2 33806152]$ cd ..
$ ls
33806152 p33806152_190000_Linux-x86-64.zip p33808367_190000_Linux-x86-64.zip p6880880_190000_Linux-x86-64.zip PatchSearch.xml
[oracle@test2 patch]$ unzip p33808367_190000_Linux-x86-64.zip
Archive: p33808367_190000_Linux-x86-64.zip
creating: 33808367/
##检查补丁是否冲突
[oracle@test2 33808367]$ $ORACLE_HOME/OPatch/opatch prereq CheckConflictAgainstOHWithDetail
Prereq "checkConflictAgainstOHWithDetail" passed.
##应用补丁
[oracle@test2 patch]$ cd 33808367/
[oracle@test2 33808367]$ $ORACLE_HOME/OPatch/opatch apply
Verifying environment and performing prerequisite checks...
OPatch continues with these patches: 33808367
##输入y
是否继续? [y|n]
y
User Responded with: Y
All checks passed.
##输入y
本地系统是否已准备打补丁? [y|n]
y
User Responded with: Y
Backing up files...
正在将临时补丁程序 '33808367' 应用于 OH '/u01/app/oracle/product/19.0.0/db_1'
...
OPatch succeeded.
6.主库备份 oracle_home目录、上传补丁包
$ mkdir -p /u01/app/patch
$ cd /u01/app/patch/
$ ls
p33806152_190000_Linux-x86-64.zip p33808367_190000_Linux-x86-64.zip p6880880_190000_Linux-x86-64.zip
$ cd $ORACLE_HOME/
$ cd ..
$ ls
db_1
$ tar -cvzf db_home.tar.g db_1/
7.主库关闭数据库及监听程序
##关闭数据库
sqlplus / as sysdba
shu immediate
exit
##关闭监听
lsnrctl stop
8.主库升级Opatch
升级操作与备库相同(主库注册补丁后切换至备库,备库自动完成补丁的注册)
##注册前的检查
[oracle@test1 OPatch]$ ./datapatch -prereq
##检查完成开始注册补丁
[oracle@test1 OPatch]$ ./datapatch -verbose
...
Validating logfiles...done
Patch 33806152 apply: SUCCESS logfile: /u01/app/oracle/cfgtoollogs/sqlpatch/33806152/24713297/33806152_apply_ORCL_2022Jul18_17_28_09.log (no errors)
Patch 33808367 apply: SUCCESS logfile: /u01/app/oracle/cfgtoollogs/sqlpatch/33808367/24680225/33808367_apply_ORCL_2022Jul18_17_27_35.log (no errors)
SQL Patching tool complete on Mon Jul 18 17:38:42 2022
##注册完成无报错
9.编译无效对象
$ cd $ORACLE_HOME//rdbms/admin
$ sqlplus /nolog
SQL> CONNECT / AS SYSDBA
Connected.
SQL> @utlrp.sql
......
ERRORS DURING RECOMPILATION
---------------------------
0
Function created.
PL/SQL procedure successfully completed.
Function dropped.
PL/SQL procedure successfully completed.
##无效对象编译完成
10.检查主库的补丁注册情况
SQL> select VERSION,VERSION_FULL from dba_registry;
VERSION VERSION_FULL
------------------------------ ------------------------------
19.0.0.0.0 19.15.0.0.0
19.0.0.0.0 19.15.0.0.0
19.0.0.0.0 19.15.0.0.0
19.0.0.0.0 19.15.0.0.0
......
11.备库切换主库完成补丁注册
##登录dgmgrl切换备库为主库
[oracle@test2 ~]$ dgmgrl sys/oracle@XXX2
DGMGRL> SWITCHOVER TO XXX2;
Switchover succeeded, new primary is "xxx2"
##检查备库补丁注册情况
SQL> select VERSION,VERSION_FULL from dba_registry;
VERSION VERSION_FULL
------------------------------ ------------------------------
19.0.0.0.0 19.15.0.0.0
19.0.0.0.0 19.15.0.0.0
19.0.0.0.0 19.15.0.0.0
19.0.0.0.0 19.15.0.0.0
19.0.0.0.0 19.15.0.0.0
19.0.0.0.0 19.15.0.0.0
19.0.0.0.0 19.15.0.0.0
......
12.切换恢复之前主备状态
##登录dgmgrl切换至原主库
$ dgmgrl sys/oracle@XXX1
DGMGRL> SWITCHOVER TO XXX1;
SQL> select DATABASE_ROLE,DB_UNIQUE_NAME,OPEN_MODE from v$database;
DATABASE_ROLE DB_UNIQUE_NAME OPEN_MODE
---------------- ------------------------------ --------------------
PRIMARY XXX1 READ WRITE
##如果检查同步状态不正常切换一次日志
SQL> alter system switch logfile;
————————————————
版权声明:本文为CSDN博主「森森淼淼丶」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_61212661/article/details/130227461