一、概述
参考文章
- https://www.cnblogs.com/andy6/p/5915907.html
- Patch 31537677 Readme文档
补丁说明
Oracle数据库补丁一般分为两种,CPU和PSU。
- CPU
CPU的全称是Critical Patch Update,Oracle对于其产品每个季度发行一次安全补丁包,通常是为了修复产品中的安全隐患。CPU
是累积的,即最新的CPU补丁已经包含以往的CPU补丁,所以只要安装最新的CPU补丁即可。
- PSU
PSU全称是Patch Set Update,Oracle对于其产品每个季度发行一次的补丁包,包含了bug的修复。Oracle选取被用户下载数量多,且被验证过具有较低风险的补丁放入到每个季度的PSU中。在每个PSU中不但包含bug的修复而且还包含了最新的CPU。PSU通常随
CPU一起发布。PSU通常也是增量的,大部分可以直接安装,但有些PSU则必须安装了上一个版本的PSU之后才能继续安装,要仔细查看各个PSU的Readme文档。
数据库环境
- 操作系统版本:Red Hat Enterprise Linux Server release 6.5
- 数据库版本:11.2.0.4.0
- 查询当前系统补丁安装信息:
[yaya@yaya ~]$ cd $ORACLE_HOME
[yaya@yaya db_1]$ cd OPatch/
[yaya@yaya OPatch]$ opatch lsinventory
Oracle Interim Patch Installer version 11.2.0.3.4
Copyright (c) 2012, Oracle Corporation. All rights reserved.
Oracle Home : /opt/app/oracle/product/11.2.0/db_1
Central Inventory : /opt/app/oracle/inventory
from : /opt/app/oracle/product/11.2.0/db_1/oraInst.loc
OPatch version : 11.2.0.3.4
OUI version : 11.2.0.4.0
Log file location : /opt/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2022-03-04_11-21-26AM_1.log
Lsinventory Output file location : /opt/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/lsinv/lsinventory2022-03-04_11-21-26AM.txt
--------------------------------------------------------------------------------
Installed Top-level Products (1):
Oracle Database 11g 11.2.0.4.0
There are 1 products installed in this Oracle Home.
There are no Interim patches installed in this Oracle Home.
--------------------------------------------------------------------------------
OPatch succeeded.
[yaya@yaya OPatch]$
补丁文件
- OPatch:p6880880_112000_Linux-x86-64.zip
- Database PSU:p31537677_112040_Linux-x86-64.zip
二、实施安装
安装步骤
- 下载补丁及OPatch工具;
- 上传补丁相关文件到服务器;
- 停止所有数据库服务、业务系统;
- 备份Oracle软件(备份ORACLE_HOME目录),生产环境已有数据的,建议做一次数据全备;
- 替换原来的OPatch工具;
- 安装补丁;(根据补丁说明文档进行安装,一般先在测试环境安装,没问题之后再安装到生产)
- 检查补丁安装情况;
- 启动数据库服务;
- 测试应用。
备份Oracle软件
在应用补丁集或补丁之前,一般都建议备份ORACLE_HOME二进制文件以及Central Inventory(oraInventory)文件。备份必须由Oracle安装用户或root用户进行,以确保正确保留文件的所有权/权限。在备份之前,一般建议关闭数据库服务、监听器以及所有数据库进程,确保Oracle Home软件冷备顺利进行。
1. 进入ORACLE_HOME所在目录:
[yaya@yaya ~]$ cd $ORACLE_HOME
[yaya@yaya db_1]$ pwd
/opt/app/oracle/product/11.2.0/db_1
[yaya@yaya db_1]$ cd ..
[yaya@yaya 11.2.0]$
2. 备份ORACLE_HOME:
[yaya@yaya 11.2.0]$ tar -pcvf /opt/app/oracle/backup/db_1_bak.tar db_1
3. 备份Central Inventory也应该是备份计划的一部分,并与Oracle_Home备份同时进行,以保持一致性。
4. 一般在/var/opt/oracle/oraInst.loc 或 /etc/oraInst.loc文件中可以查看Central Inventory的位置:
[yaya@yaya etc]$ cat oraInst.loc
inventory_loc=/opt/app/oracle/inventory
inst_group=oinstall
OPatch安装
查看当期OPatch工具版本:
[yaya@yaya ~]$ cd $ORACLE_HOME
[yaya@yaya db_1]$ cd OPatch/
[yaya@yaya OPatch]$ opatch version
OPatch Version: 11.2.0.3.4
OPatch succeeded.
上传OPatch安装包:
sftp:/soft> put F:\system\oracle\Oracle11.2.0.4\PSU\OPtach\p6880880_112000_Linux-x86-64.zip
Uploading p6880880_112000_Linux-x86-64.zip to remote:/soft/p6880880_112000_Linux-x86-64.zip
sftp: sent 117 MB in 10.56 seconds
sftp:/soft> put F:\system\oracle\Oracle11.2.0.4\PSU\DB\p31537677_112040_Linux-x86-64.zip
Uploading p31537677_112040_Linux-x86-64.zip to remote:/soft/p31537677_112040_Linux-x86-64.zip
sftp: sent 373 MB in 30.58 seconds
解压OPatch安装包并赋权:
[root@yaya soft]# unzip p6880880_112000_Linux-x86-64.zip
[root@yaya soft]# ls
OPatch p31537677_112040_Linux-x86-64.zip p6880880_112000_Linux-x86-64.zip
[root@yaya soft]# chown -R yaya:oinstall OPatch/
[root@yaya soft]# ll
total 502468
drwxr-x--- 16 yaya oinstall 4096 Feb 1 2021 OPatch
-rw-r--r-- 1 root root 391781147 Mar 4 11:38 p31537677_112040_Linux-x86-64.zip
-rw-r--r-- 1 root root 122739146 Mar 4 11:37 p6880880_112000_Linux-x86-64.zip
替换原OPatch目录:
[root@yaya ~]# cd /opt/app/oracle/product/11.2.0/db_1 [root@yaya db_1]# mv OPatch/ OPatchBak/ [root@yaya db_1]# mv /soft/OPatch/ ./
查看目前OPatch版本:
[yaya@yaya db_1]$ opatch version
OPatch Version: 11.2.0.3.28
OPatch succeeded.
[yaya@yaya db_1]$
PSU补丁安装
补丁包解压缩:
[root@yaya soft]# unzip p31537677_112040_Linux-x86-64.zip
为补丁包赋权:
[root@yaya soft]# chown -R yaya:oinstall 31537677/
[root@yaya soft]# ll
total 502608
drwxr-xr-x 30 yaya oinstall 4096 Sep 24 2020 31537677
检查补丁兼容性:
[yaya@yaya soft]$ cd 31537677/
[yaya@yaya 31537677]$ opatch prereq CheckConflictAgainstOHWithDetail -ph ./
Oracle Interim Patch Installer version 11.2.0.3.28
Copyright (c) 2022, Oracle Corporation. All rights reserved.
PREREQ session
Oracle Home : /opt/app/oracle/product/11.2.0/db_1
Central Inventory : /opt/app/oracle/inventory
from : /opt/app/oracle/product/11.2.0/db_1/oraInst.loc
OPatch version : 11.2.0.3.28
OUI version : 11.2.0.4.0
Log file location : /opt/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2022-03-08_10-31-08AM_1.log
Invoking prereq "checkconflictagainstohwithdetail"
Prereq "checkConflictAgainstOHWithDetail" passed.
OPatch succeeded.
安装补丁(Oracle Home):
[yaya@yaya 31537677]$ opatch apply
Oracle Interim Patch Installer version 11.2.0.3.28
Copyright (c) 2022, Oracle Corporation. All rights reserved.
Oracle Home : /opt/app/oracle/product/11.2.0/db_1
Central Inventory : /opt/app/oracle/inventory
from : /opt/app/oracle/product/11.2.0/db_1/oraInst.loc
OPatch version : 11.2.0.3.28
OUI version : 11.2.0.4.0
Log file location : /opt/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2022-03-08_10-36-50AM_1.log
Verifying environment and performing prerequisite checks...
OPatch continues with these patches: 17478514 18031668 18522509 19121551 19769489 20299013 20760982 21352635 21948347 22502456 23054359 24006111 24732075 25869727 26609445 26392168 26925576 27338049 27734982 28204707 28729262 29141056 29497421 29913194 30298532 30670774 31103343 31537677
Do you want to proceed? [y|n]
y
User Responded with: Y
All checks passed.
Please shutdown Oracle instances running out of this ORACLE_HOME on the local system.
(Oracle Home = '/opt/app/oracle/product/11.2.0/db_1')
Is the local system ready for patching? [y|n]
......
......
......
OPatch found the word "error" in the stderr of the make command.
Please look at this stderr. You can re-run this make command.
Stderr output:
chmod: changing permissions of `/opt/app/oracle/product/11.2.0/db_1/bin/extjobO': Operation not permitted
make: [iextjob] Error 1 (ignored)
Composite patch 31537677 successfully applied.
OPatch Session completed with warnings.
Log file location: /opt/app/oracle/product/11.2.0/db_1/cfgtoollogs/opatch/opatch2022-03-08_10-36-50AM_1.log
OPatch completed with warnings.
[yaya@yaya 31537677]$
注:
注意检查是否出现error,一般出现warnings不会有啥问题。
安装补丁(Database):
[yaya@yaya ~]$ cd $ORACLE_HOME/rdbms/admin
[yaya@yaya admin]$ sqlplus / as sysdba
SQL> STARTUP
SQL> @catbundle.sql psu apply
...
注:
执行catbundle.sql脚本的时候可能会出现以下可忽略错误:
ORA-00942: table or view does not exist
ORA-00955: name is already used by an existing object
ORA-01430: column being added already exists in table
ORA-01432: public synonym to be dropped does not exist
ORA-01434: private synonym to be dropped does not exist
ORA-01435: user does not exist
ORA-01917: user or role 'XDB' does not exist
ORA-01920: user name '<user-name>' conflicts with another user or role name
ORA-01921: role name '<role name>' conflicts with another user or role name
ORA-01927: cannot REVOKE privileges you did not grant
ORA-01952: system privileges not granted to 'WKSYS'
ORA-02303: cannot drop or replace a type with type or table dependents
ORA-02443: Cannot drop constraint - nonexistent constraint
ORA-04043: object <object-name> does not exist
ORA-06512: at line <line number>. (That is, if ORA-06512 follows any of preceding errors, it can be safely ignored.)
ORA-14452: attempt to create, alter or drop an index on temporary table already in use
ORA-29809: cannot drop an operator with dependent objects
ORA-29830: operator does not exist
ORA-29832: cannot drop or replace an indextype with dependent indexes
ORA-29844: duplicate operator name specified
ORA-29931: specified association does not exist
检查补丁安装情况:
set line 150
set pagesize 99
col action_time for a30
col action for a30
col comments for a90
col object_name for a30
col object_type for a30
col comp_name for a50
col comp_id for a20
spool post_check.log
1. 查看实例信息及状态:
select instance_name,status from v$instance;
2. 查看数据库版本:
select * from v$version;
3. 查看数据库大小:
select sum(bytes)/1024/1024||'M' from dba_segments;
4. 查看组件信息:
select COMP_ID,COMP_NAME,VERSION,STATUS from DBA_REGISTRY;
5. 查看补丁情况:
select ACTION_TIME, ACTION, COMMENTS from DBA_REGISTRY_HISTORY;
6. 查看无效对象:
select owner,object_name,object_type,status from dba_objects where status<>'VALID';
select count(*) from dba_objects where status<>'VALID';
spool off
如下:
SQL> set lines 200
SQL> col comments for a20
SQL> select ACTION_TIME, ACTION, COMMENTS from DBA_REGISTRY_HISTORY;
ACTION_TIME ACTION COMMENTS
------------------------------ ------------------------------ --------------------
21-NOV-21 12.48.10.876472 AM APPLY Patchset 11.2.0.2.0
08-MAR-22 11.04.41.987022 AM APPLY PSU 11.2.0.4.201020
补丁回退
- 查看catbundle_PSU_
_ROLLBACK.sql文件是否存在每个数据库的ORACLE_HOME下(如果不存在,在卸载补丁之前必须再次执行@catbundle.sql步骤):
[yaya@yaya ~]$ cd $ORACLE_HOME/rdbms/admin
[yaya@yaya admin]$ ls | grep "catbundle"
catbundleapply.sql
catbundle_exa.sql
catbundle_PSU_ORCL_APPLY.sql
catbundle_PSU_ORCL_ROLLBACK.sql
catbundle_psu.sql
catbundle.sql
- 关闭实例和监听;
lsnrctl stop
shutdown immediate;
- 执行以下命令rollback:
opatch rollback -id 31537677
- 为数据库实例执行回退脚本:
cd $ORACLE_HOME/rdbms/admin
sqlplus / as sysdba
SQL> startup
SQL> @catbundle_PSU_ORCL_ROLLBACK.sql
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




