1. 首页 > Oracle教程 > 正文

Oracle教程FG193-CPU/PSU应用

本文详细介绍Oracle数据库CPU/PSU补丁的应用方法,包括单实例和RAC环境的实施步骤。风哥教程参考Oracle官方文档Security、Install and Upgrade等内容。

Part01-基础概念与理论知识

1.1 CPU/PSU概念与区别

CPU(Critical Patch Update)是Oracle定期发布的安全补丁集合,主要解决安全漏洞;PSU(Patch Set Update)包含CPU的所有安全补丁,同时还包含非安全漏洞的修复,学习交流加群风哥微信: itpux-com。

# 查看当前数据库版本和补丁信息
$ sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 – Production on Fri Mar 29 10:00:00 2026
Version 19.3.0.0.0

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

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 – Production
Version 19.3.0.0.0

SQL> select * from v$version;BANNER
——————————————————————————–
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 – Production
PL/SQL Release 19.0.0.0.0 – Production
CORE 19.0.0.0.0 Production
TNS for Linux: Version 19.0.0.0.0 – Production
NLSRTL Version 19.0.0.0.0 – Production

SQL> select patch_id, patch_type, action_time from dba_registry_sqlpatch order by action_time desc;no rows selected
SQL>

1.2 Oracle补丁分类

Oracle补丁主要分为以下几类:

  • CPU:安全补丁,每月发布
  • PSU:包含CPU的累积补丁,每季度发布
  • RU:Release Update,包含PSU的所有内容,每季度发布
  • RUR:Release Update Revision,修复RU中的问题,每月发布
  • OJVM PSU:Oracle JVM补丁,每季度发布
  • One-off:单个问题的修复补丁

1.3 补丁发布周期

Oracle的补丁发布周期为:

  • CPU:每月的第二个星期二
  • PSU/RU:每年的1月、4月、7月、10月
  • RUR:每月发布,修复上一个RU的问题

Part02-生产环境规划与建议

2.1 应用前检查清单

在应用CPU/PSU补丁前,需要进行以下检查:

  • 数据库版本兼容性
  • OPatch工具版本
  • 空间检查
  • 备份状态
  • 数据库健康状态
# 检查OPatch版本
$ $ORACLE_HOME/OPatch/opatch version

OPatch Version: 12.2.0.1.23

OPatch succeeded.

# 检查数据库健康状态
$ sqlplus / as sysdba

SQL> select status from v$instance;STATUS
————
OPEN

SQL> select name, status from v$database;NAME STATUS
——— ————
FGEDUDB OPEN

SQL> select count(*) from v$session where status=’ACTIVE’;COUNT(*)
———-
12

# 检查空间情况
SQL> select tablespace_name, sum(bytes)/1024/1024 as mb_used, sum(maxbytes)/1024/1024 as mb_max from dba_data_files group by tablespace_name;TABLESPACE_NAME MB_USED MB_MAX
—————————— ———- ———-
SYSTEM 880 32768
SYSAUX 1210 32768
UNDOTBS1 100 32768
USERS 10 32768
FGEDU_DATA 200 32768

生产环境建议:应用补丁前必须确保有完整的数据库备份,包括控制文件、数据文件和归档日志。同时,建议在测试环境先验证补丁的兼容性。

2.2 补丁选择策略

选择补丁时应考虑以下因素:

  • 数据库版本和平台
  • 当前已应用的补丁
  • 业务需求和安全要求
  • 补丁的稳定性和兼容性

2.3 回滚计划制定

制定详细的回滚计划是确保系统安全的重要措施:

  • 备份策略和验证
  • 回滚步骤和时间估算
  • 回滚测试
  • 回滚后的验证

Part03-生产环境项目实施方案

3.1 单实例环境CPU/PSU应用

单实例环境CPU/PSU应用的步骤如下:

  1. 准备工作:备份、检查OPatch版本
  2. 关闭数据库和监听
  3. 应用补丁
  4. 运行postinstall脚本
  5. 启动数据库和监听
  6. 验证补丁

3.2 RAC环境CPU/PSU应用

RAC环境CPU/PSU应用的步骤如下:

  1. 准备工作:备份、检查OPatch版本
  2. 关闭所有节点的数据库和监听
  3. 在每个节点应用补丁
  4. 运行postinstall脚本
  5. 启动所有节点的数据库和监听
  6. 验证补丁

3.3 应用后验证

补丁应用后需要进行以下验证:

  • 数据库启动状态
  • 补丁应用状态
  • 数据库健康检查
  • 应用功能测试

Part04-生产案例与实战讲解

4.1 单实例环境补丁应用案例

以下是单实例环境应用19.12 PSU补丁的实战案例:

# 1. 准备工作:备份数据库
$ rman target /Recovery Manager: Release 19.0.0.0.0 – Production on Fri Mar 29 10:30:00 2026
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.

connected to target database: FGEDUDB (DBID=1234567890)

RMAN> backup database plus archivelog delete input;Starting backup at 29-MAR-26
current log archived
using channel ORA_DISK_1
channel ORA_DISK_1: starting archived log backup set
channel ORA_DISK_1: specifying archived log(s) in backup set
input archived log thread=1 sequence=1 RECID=1 STAMP=1234567890
input archived log thread=1 sequence=2 RECID=2 STAMP=1234567900
channel ORA_DISK_1: starting piece 1 at 29-MAR-26
channel ORA_DISK_1: finished piece 1 at 29-MAR-26
piece handle=/oracle/app/oracle/fast_recovery_area/FGEDUDB/backupset/2026_03_29/o1_mf_annnn_TAG20260329T103000_1234567890_.bkp tag=TAG20260329T103000 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:10
channel ORA_DISK_1: deleting archived log(s)
archived log file name=/oracle/app/oracle/fast_recovery_area/FGEDUDB/archivelog/2026_03_29/o1_mf_1_1_1234567890_.arc RECID=1 STAMP=1234567890
archived log file name=/oracle/app/oracle/fast_recovery_area/FGEDUDB/archivelog/2026_03_29/o1_mf_1_2_1234567900_.arc RECID=2 STAMP=1234567900
Finished backup at 29-MAR-26

Starting backup at 29-MAR-26
using channel ORA_DISK_1
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00001 name=/oracle/app/oracle/oradata/FGEDUDB/system01.dbf
input datafile file number=00002 name=/oracle/app/oracle/oradata/FGEDUDB/sysaux01.dbf
input datafile file number=00003 name=/oracle/app/oracle/oradata/FGEDUDB/undotbs01.dbf
input datafile file number=00004 name=/oracle/app/oracle/oradata/FGEDUDB/users01.dbf
input datafile file number=00005 name=/oracle/app/oracle/oradata/FGEDUDB/fgedu_data01.dbf
channel ORA_DISK_1: starting piece 1 at 29-MAR-26
channel ORA_DISK_1: finished piece 1 at 29-MAR-26
piece handle=/oracle/app/oracle/fast_recovery_area/FGEDUDB/backupset/2026_03_29/o1_mf_nnndf_TAG20260329T103010_1234567910_.bkp tag=TAG20260329T103010 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:05:30
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
including current control file in backup set
including current SPFILE in backup set
channel ORA_DISK_1: starting piece 1 at 29-MAR-26
channel ORA_DISK_1: finished piece 1 at 29-MAR-26
piece handle=/oracle/app/oracle/fast_recovery_area/FGEDUDB/backupset/2026_03_29/o1_mf_ncsnf_TAG20260329T103010_1234567960_.bkp tag=TAG20260329T103010 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:15
Finished backup at 29-MAR-26

RMAN> exit

# 2. 关闭数据库和监听
$ sqlplus / as sysdba

SQL> shutdown immediate;Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> exit

$ lsnrctl stop

LSNRCTL for Linux: Version 19.0.0.0.0 – Production on 29-MAR-2026 10:36:00
Copyright (c) 1991, 2019, Oracle. All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=fgedu.net.cn)(PORT=1521)))
The command completed successfully

# 3. 应用补丁
$ unzip p32904851_190000_Linux-x86-64.zip -d /oracle/soft
$ cd /oracle/soft/32904851
$ $ORACLE_HOME/OPatch/opatch apply

Oracle Interim Patch Installer version 12.2.0.1.23
Copyright (c) 2026, Oracle Corporation. All rights reserved.

Oracle Home : /oracle/app/oracle/product/19c/db_1
Central Inventory : /oracle/app/oraInventory
from : /oracle/app/oracle/product/19c/db_1/oraInst.loc
OPatch version : 12.2.0.1.23
OUI version : 12.2.0.7.0
Log file location : /oracle/app/oracle/product/19c/db_1/cfgtoollogs/opatch/opatch2026-03-29_103700_AM.log

Verifying environment and performing prerequisite checks…
Prerequisite check “CheckMinimumOPatchVersion” passed.
Prerequisite check “CheckActiveFilesAndExecutables” passed.

Do you want to proceed? [y|n] y
User Responded with: Y
Applying interim patch ‘32904851’ to OH ‘/oracle/app/oracle/product/19c/db_1’
Patching component oracle.rdbms.rsf, 19.0.0.0.0…
Patching component oracle.rdbms, 19.0.0.0.0…
Patching component oracle.rdbms.dv, 19.0.0.0.0…
Patching component oracle.rdbms.rman, 19.0.0.0.0…
Patching component oracle.rdbms.rat, 19.0.0.0.0…
Patching component oracle.rdbms.crs, 19.0.0.0.0…
Patching component oracle.rdbms.deconfig, 19.0.0.0.0…
Patching component oracle.rdbms.dbscripts, 19.0.0.0.0…

OPatch succeeded.

# 4. 运行postinstall脚本
$ cd $ORACLE_HOME/sqlpatch/32904851
$ sqlplus / as sysdba

SQL> startup
ORACLE instance started.

Total System Global Area 8589934592 bytes
Fixed Size 9135808 bytes
Variable Size 4294967296 bytes
Database Buffers 4278190080 bytes
Redo Buffers 7639040 bytes
Database mounted.
Database opened.

SQL> alter session set container=CDB$ROOT;Session altered.

SQL> @postinstall.sql

PL/SQL procedure successfully completed.

SQL> select status from dba_registry_sqlpatch where patch_id=32904851;STATUS
——–
SUCCESS

SQL> exit

# 5. 启动监听
$ lsnrctl start

LSNRCTL for Linux: Version 19.0.0.0.0 – Production on 29-MAR-2026 10:45:00
Copyright (c) 1991, 2019, Oracle. All rights reserved.

Starting /oracle/app/oracle/product/19c/db_1/bin/tnslsnr: please wait…

TNSLSNR for Linux: Version 19.0.0.0.0 – Production
System parameter file is /oracle/app/oracle/product/19c/db_1/network/admin/listener.ora
Log messages written to /oracle/app/oracle/diag/tnslsnr/fgedu/listener/alert/log.xml
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=fgedu.net.cn)(PORT=1521)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=fgedu.net.cn)(PORT=1521)))
STATUS of the LISTENER
————————
Alias LISTENER
Version TNSLSNR for Linux: Version 19.0.0.0.0 – Production
Start Date 29-MAR-2026 10:45:00
Uptime 0 days 0 hr. 0 min. 0 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /oracle/app/oracle/product/19c/db_1/network/admin/listener.ora
Listener Log File /oracle/app/oracle/diag/tnslsnr/fgedu/listener/alert/log.xml
Listening Endpoints Summary…
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=fgedu.net.cn)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully

# 6. 验证补丁
$ $ORACLE_HOME/OPatch/opatch lspatches

32904851;Database Release Update : 19.12.0.0.210720 (32904851)

OPatch succeeded.

$ sqlplus / as sysdba

SQL> select patch_id, patch_type, action_time from dba_registry_sqlpatch order by action_time desc;PATCH_ID PATCH_TYPE ACTION_TIME
———- ———— ——————-
32904851 RU 2026-03-29 10:43:20

SQL>

风哥提示:应用补丁时,建议使用最新版本的OPatch工具,以避免兼容性问题。可以从My Oracle Support下载最新版本的OPatch。

4.2 RAC环境补丁应用案例

以下是2节点RAC环境应用19.12 PSU补丁的实战案例:

# 节点1操作:
# 1. 备份数据库
$ rman target /Recovery Manager: Release 19.0.0.0.0 – Production on Fri Mar 29 11:00:00 2026
Version 19.3.0.0.0

Copyright (c) 1982, 2019, Oracle and/or its affiliates. All rights reserved.

connected to target database: FGEDURAC (DBID=1234567890)

RMAN> backup database plus archivelog delete input;# 备份过程略…

# 2. 检查集群状态
$ crsctl stat res -t

——————————————————————————–
Name Target State Server State details
——————————————————————————–
Local Resources
——————————————————————————–
ora.DGDATA01.dg
ONLINE ONLINE fgedurac1 STABLE
ONLINE ONLINE fgedurac2 STABLE
ora.DGSYSTEM.dg
ONLINE ONLINE fgedurac1 STABLE
ONLINE ONLINE fgedurac2 STABLE
ora.LISTENER.lsnr
ONLINE ONLINE fgedurac1 STABLE
ONLINE ONLINE fgedurac2 STABLE
ora.asm
ONLINE ONLINE fgedurac1 Started,STABLE
ONLINE ONLINE fgedurac2 Started,STABLE
ora.chad
ONLINE ONLINE fgedurac1 STABLE
ONLINE ONLINE fgedurac2 STABLE
ora.net1.network
ONLINE ONLINE fgedurac1 STABLE
ONLINE ONLINE fgedurac2 STABLE
ora.ons
ONLINE ONLINE fgedurac1 STABLE
ONLINE ONLINE fgedurac2 STABLE
ora.python
offline offline fgedurac1 STABLE
ONLINE ONLINE fgedurac2 STABLE
——————————————————————————–
Cluster Resources
——————————————————————————–
ora.ASMNET1LSNR_ASM.lsnr(ora.asmgroup)
1 ONLINE ONLINE fgedurac1 STABLE
2 ONLINE ONLINE fgedurac2 STABLE
ora.CRS.cluster_resource
1 ONLINE ONLINE fgedurac1 STABLE
2 ONLINE ONLINE fgedurac2 STABLE
ora.FGEDURAC.db
1 ONLINE ONLINE fgedurac1 Open,HOME=/oracle/app/oracle/product/19c/db_1,STABLE
2 ONLINE ONLINE fgedurac2 Open,HOME=/oracle/app/oracle/product/19c/db_1,STABLE
ora.LISTENER_SCAN1.lsnr
offline offline STABLE
ora.asm-cvu.resource
1 ONLINE ONLINE fgedurac1 STABLE
2 ONLINE ONLINE fgedurac2 STABLE
ora.cvu
offline offline STABLE
ora.qosmserver
1 ONLINE ONLINE fgedurac1 STABLE
ora.scan1.vip
offline offline STABLE
——————————————————————————–

# 3. 关闭数据库实例(保留CRS和ASM运行)
$ srvctl stop database -d FGEDURAC

# 4. 应用补丁(在两个节点上分别执行)
# 节点1:
$ unzip p32904851_190000_Linux-x86-64.zip -d /oracle/soft
$ cd /oracle/soft/32904851
$ $ORACLE_HOME/OPatch/opatch apply -local

# 节点2:
$ unzip p32904851_190000_Linux-x86-64.zip -d /oracle/soft
$ cd /oracle/soft/32904851
$ $ORACLE_HOME/OPatch/opatch apply -local

# 5. 运行postinstall脚本(在任意节点执行)
$ sqlplus / as sysdba

SQL> startup
ORACLE instance started.

SQL> alter session set container=CDB$ROOT;Session altered.

SQL> @$ORACLE_HOME/sqlpatch/32904851/postinstall.sql

PL/SQL procedure successfully completed.

# 6. 启动数据库
$ srvctl start database -d FGEDURAC

# 7. 验证补丁
$ $ORACLE_HOME/OPatch/opatch lspatches

32904851;Database Release Update : 19.12.0.0.210720 (32904851)

OPatch succeeded.

$ sqlplus / as sysdba

SQL> select patch_id, patch_type, action_time from dba_registry_sqlpatch order by action_time desc;PATCH_ID PATCH_TYPE ACTION_TIME
———- ———— ——————-
32904851 RU 2026-03-29 11:30:15

SQL>

4.3 常见问题与解决方案

应用补丁过程中常见的问题及解决方案:

# 问题1:OPatch版本过低

$ $ORACLE_HOME/OPatch/opatch apply

OPatch Version: 12.2.0.1.19

Oracle Home : /oracle/app/oracle/product/19c/db_1
Central Inventory : /oracle/app/oraInventory
from : /oracle/app/oracle/product/19c/db_1/oraInst.loc
OPatch version : 12.2.0.1.19
OUI version : 12.2.0.7.0
Log file location : /oracle/app/oracle/product/19c/db_1/cfgtoollogs/opatch/opatch2026-03-29_120000_AM.log

Verifying environment and performing prerequisite checks…
Prerequisite check “CheckMinimumOPatchVersion” failed.
The details are:

Minimum OPatch Version required is 12.2.0.1.23. OPatch Version is 12.2.0.1.19.
Please upgrade OPatch using the OPatch Utility Release Update 12.2.0.1.23 or later.

OPatch failed with error code 73

# 解决方案:下载并安装最新版本的OPatch
$ unzip p6880880_190000_Linux-x86-64.zip -d /oracle/soft
$ cp -r /oracle/soft/OPatch/* $ORACLE_HOME/OPatch/$ $ORACLE_HOME/OPatch/opatch version

OPatch Version: 12.2.0.1.23

OPatch succeeded.

# 问题2:补丁冲突

$ $ORACLE_HOME/OPatch/opatch apply

Oracle Interim Patch Installer version 12.2.0.1.23
Copyright (c) 2026, Oracle Corporation. All rights reserved.

Oracle Home : /oracle/app/oracle/product/19c/db_1
Central Inventory : /oracle/app/oraInventory
from : /oracle/app/oracle/product/19c/db_1/oraInst.loc
OPatch version : 12.2.0.1.23
OUI version : 12.2.0.7.0
Log file location : /oracle/app/oracle/product/19c/db_1/cfgtoollogs/opatch/opatch2026-03-29_121000_AM.log

Verifying environment and performing prerequisite checks…
Prerequisite check “CheckConflictWithExistingPatches” failed.
The details are:

There are patches already applied to the Oracle Home (ORACLE_HOME) which conflict with the current patch being applied. The patches are:

32895461;Database Release Update : 19.11.0.0.210420 (32895461)

Do you want to proceed? [y|n] n
User Responded with: N

OPatch failed with error code 74

# 解决方案:PSU/RU补丁是累积的,直接应用较新的补丁即可,会自动替换旧补丁

$ $ORACLE_HOME/OPatch/opatch apply -force

# 或查看冲突详情后决定是否继续
$ $ORACLE_HOME/OPatch/opatch prereq CheckConflictAgainstOHWithDetail -phBaseDir /oracle/soft/32904851

Part05-风哥经验总结与分享

1. 补丁应用前必须进行完整的备份,包括数据库、控制文件和归档日志,以确保在出现问题时能够快速恢复。更多视频教程www.fgedu.net.cn

2. 建议在测试环境先验证补丁的兼容性和稳定性,特别是对于生产环境的关键应用。

3. 应用补丁时,应使用最新版本的OPatch工具,以避免兼容性问题。

4. 对于RAC环境,需要在所有节点上应用补丁,并确保集群服务的正常运行。

5. 补丁应用后,需要进行全面的验证,包括数据库状态、补丁应用状态和应用功能测试。

6. 制定详细的回滚计划,以便在补丁应用失败时能够快速回滚到之前的状态。

7. 定期关注Oracle的补丁发布信息,及时应用安全补丁,以保护数据库免受安全威胁。学习交流加群风哥QQ113257174

8. 对于大型生产环境,建议分阶段应用补丁,先在部分节点或数据库上应用,验证无误后再全面推广。

风哥提示:补丁应用是数据库维护的重要组成部分,需要认真规划和执行,以确保系统的安全性和稳定性。

更多学习教程公众号风哥教程itpux_com。from oracle:www.itpux.com

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息