Oracle-11g升级PSU补丁

Oracle 11g 数据库软件PSU升级

1. PSU补丁升级过程

1.1 升级opatch工具

1.1.1 GI环境

# GI HOME
su - root
# 配置环境
export GI_HOME=$(grep ‘^+ASM‘ /etc/oratab |awk -F: ‘{ print $2 }‘) && echo ${GI_HOME}
# 备份和解压
[[ -d "${GI_HOME}/OPatch" ]] && mv ${GI_HOME}/OPatch ${GI_HOME}/OPatch_$(date +%Y%m%d) && [[ -f "$(ls p6880880_*_Linux-x86-64.zip)" ]] && unzip -qo p6880880_*_Linux-x86-64.zip -d ${GI_HOME}
# 检查确认
ls -ld ${GI_HOME}/OPatch*
chown -R grid:oinstall ${GI_HOME}/OPatch
chmod -R +x ${GI_HOME}/OPatch
ls -ld ${GI_HOME}/OPatch*
su - grid -c "opatch version"

# --创建响应文件(2161861.1, 从11.2.0.3.14开始静默应用补丁不再需要响应文件)
su - grid
[[ -f "${ORACLE_HOME}/OPatch/ocm/bin/emocmrsp" ]] && (sleep 3;echo -e ‘\n‘;sleep 3;echo -e ‘Y\n‘)|${ORACLE_HOME}/OPatch/ocm/bin/emocmrsp -no_banner -output /tmp/ocm.rsp

1.1.2 DB 环境

# DB HOME
su - oracle
# 备份
[[ -d "${ORACLE_HOME}/OPatch" ]] && mv ${ORACLE_HOME}/OPatch ${ORACLE_HOME}/OPatch_$(date +%Y%m%d)
ls -ld ${ORACLE_HOME}/OPatch*
# 解压
unzip -oq p6880880_*_Linux-x86-64.zip -d ${ORACLE_HOME}
# 检查
ls -ld ${ORACLE_HOME}/OPatch*
${ORACLE_HOME}/OPatch/opatch version

1.2 应用PSU二进制文件

1.2.1 opatch auto方式(适用RAC)

su - root
. /home/grid/.bash_profile
export GI_HOME=$(grep ‘^+ASM‘ /etc/oratab |awk -F: ‘{ print $2 }‘)
export DB_HOME=$(grep -Ev ‘^#|^$|+ASM‘ /etc/oratab |awk -F: ‘{ print $2 }‘)
# su - grid -c "(sleep 3;echo -e ‘\n‘;sleep 3;echo -e ‘Y\n‘)|${GI_HOME}/OPatch/ocm/bin/emocmrsp -no_banner -output /tmp/ocm.rsp"
su - grid -c "unzip -oq p28317141_112040_Linux-x86-64.zip -d /apps/soft"
export UNZIPPED_PATCH_LOCATION=/apps/soft/28317141
export LANG=C
${GI_HOME}/OPatch/opatch auto ${UNZIPPED_PATCH_LOCATION}/27967757 -ocmrf /tmp/ocm.rsp

# 检查确认
su - grid -c "${GI_HOME}/bin/crsctl status res -t"
su - grid -c "${GI_HOME}/OPatch/opatch lspatches;${GI_HOME}/OPatch/opatch lsinventory"
su - oracle -c "${DB_HOME}/OPatch/opatch lspatches;${DB_HOME}/OPatch/opatch lsinventory"

1.2.2 opatch(适用仅更新执行oracle home)

-- 单实例环境

su - [grid|oracle]
export PATH=${ORACLE_HOME}/OPatch:${PATH}
export PATCH_PATH=/tmp/27870645
# 解压
unzip p27870645_112040_<platform>.zip -C /tmp/
# 冲突检测
cd ${PATCH_PATH}
opatch prereq CheckConflictAgainstOHWithDetail -ph ./

# 安装补丁
opatch apply

# 结果检查
opatch lsinventory

# 启动服务
sqlplus "/ as sysdba" <<-EOF
startup;
quit;
EOF

1.2.3 手工应用补丁

# 1. 关闭DB服务
su - oracle
${ORACLE_HOME}/bin/srvctl stop home -o ${ORACLE_HOME} -s <status file location> -n <node name>

# 2. 关闭集群
su - root
. /home/grid/.bash_profile
${ORACLE_HOME}/crs/install/rootcrs.pl -unlock

# 3. 应用补丁 GI HOME (可能需要 -ocmrf 选项)
su - grid
${ORACLE_HOME}/OPatch/opatch napply -oh ${ORACLE_HOME} -local <UNZIPPED_PATCH_LOCATION>/<GI_PSU_number>/<OCW Components_number>

${ORACLE_HOME}/OPatch/opatch napply -oh ${ORACLE_HOME} -local <UNZIPPED_PATCH_LOCATION>/<GI_PSU_number>/<ACFS Components_number>

${ORACLE_HOME}/OPatch/opatch apply -oh ${ORACLE_HOME} -local <UNZIPPED_PATCH_LOCATION>/<GI_PSU_number>/<DB_PSU_number>

# 4. 应用补丁 DB HOME
su - oracle
<UNZIPPED_PATCH_LOCATION>/<GI_PSU_number>/<OCW Components_number>/custom/server/<OCW Components_number>/custom/scripts/prepatch.sh -dbhome <ORACLE_HOME>

${ORACLE_HOME}/OPatch/opatch napply -oh ${ORACLE_HOME} -local <UNZIPPED_PATCH_LOCATION>/<GI_PSU_number>/<OCW Components_number>/custom/server/<OCW Components_number>
${ORACLE_HOME}/OPatch/opatch apply -oh ${ORACLE_HOME} -local <UNZIPPED_PATCH_LOCATION>/<GI_PSU_number>/<DB_PSU_number>

<UNZIPPED_PATCH_LOCATION>/<GI_PSU_number>/<OCW Components_number>/custom/server/<OCW Components_number>/custom/scripts/postpatch.sh -dbhome <ORACLE_HOME>

# 5. 启动集群服务
su - root
. /home/grid/.bash_profile
${ORACLE_HOME}/rdbms/install/rootadd_rdbms.sh
${ORACLE_HOME}/crs/install/rootcrs.pl -patch

# 6. 启动DB服务
su - oracle
${ORACLE_HOME}/bin/srvctl start home -o <ORACLE_HOME> -s <status file location> -n <node name>

1.3 更新数据字典

su - oracle
sqlplus /nolog << EOF
connect / as sysdba
@?/rdbms/admin/catbundle.sql psu apply
@?/rdbms/admin/utlrp.sql
set lines 168 pages 99
col action_time for a20
col action for a15
col namespace for a12
col version for a18
col id for 99999999
col bundle_series for a15
col comments for a28
prompt db version
select to_char(t1.action_time,‘yyyy-mm-dd hh24:mi:ss‘) action_time,t1.action,t1.namespace,t1.version,id,t1.bundle_series,t1.comments from dba_registry_history t1 order by t1.action_time;
prompt 
prompt comp info
col comp_name for a48
col comp_id for a12
col version for a16
col status for a12
col modified for a20
select t2.comp_id, t2.comp_name, t2.version, t2.status, to_char(to_date(t2.modified,‘dd-mm-yyyy hh24:mi:ss‘),‘yyyy-mm-dd hh24:mi:ss‘) modified from dba_registry t2 order by t2.modified,t2.comp_id;
quit;
EOF

1.4 应用OJVM补丁

su - oracle

# 关闭db home的所有服务
srvctl stop database -d orcl

# 冲突检查
PATCH_TOP_DIR=/apps/soft/28317141
cd ${PATCH_TOP_DIR}/27923163
opatch prereq CheckConflictAgainstOHWithDetail -ph ./

# 安装补丁
(sleep 3;echo -e ‘Y\n‘;sleep 3;echo -e ‘\n‘;sleep 3;echo -e ‘Y\n‘;sleep 3;echo -e ‘Y\n‘)|${ORACLE_HOME}/OPatch/opatch apply

# 结果检查确认
${ORACLE_HOME}/OPatch/opatch lspatches;${ORACLE_HOME}/OPatch/opatch lsinventory

# 更新数据字典
sqlplus /nolog << EOF
host srvctl start instance -d orcl -i orcl1
connect / as sysdba
alter system set cluster_database=false scope=spfile;
host srvctl stop instance -d orcl -i orcl1
connect / as sysdba
startup upgrade
set lines 200
@?/sqlpatch/27923163/postinstall.sql
alter system set cluster_database=true scope=spfile;
host srvctl stop instance -d orcl -i orcl1
host srvctl start database -d orcl
connect / as sysdba
@?/rdbms/admin/utlrp.sql
set lines 168 pages 99
col action_time for a20
col action for a15
col namespace for a12
col version for a24
col id for 99999999
col bundle_series for a15
col comments for a28
prompt db version
select to_char(t1.action_time,‘yyyy-mm-dd hh24:mi:ss‘) action_time,t1.action,t1.namespace,t1.version,id,t1.bundle_series,t1.comments from dba_registry_history t1 order by t1.action_time;
prompt 
prompt comp info
col comp_name for a48
col comp_id for a12
col version for a16
col status for a12
col modified for a20
select t2.comp_id, t2.comp_name, t2.version, t2.status, to_char(to_date(t2.modified,‘dd-mm-yyyy hh24:mi:ss‘),‘yyyy-mm-dd hh24:mi:ss‘) modified from dba_registry t2 order by t2.modified,t2.comp_id;
quit;
EOF

1.5 回退步骤

1.5.1 opatch auto回滚补丁

# 回退二进制文件
export GI_HOME=$(grep ‘^+ASM‘ /etc/oratab |awk -F: ‘{ print $2 }‘)
export UNZIPPED_PATCH_LOCATION=/apps/soft/28317141
export LANG=C
${GI_HOME}/OPatch/opatch auto ${UNZIPPED_PATCH_LOCATION}/27967757 -rollback -ocmrf /tmp/ocm.rsp

# 回退数据字典
su - oracle
sqlplus /nolog << EOF
connect / as sysdba
COLUMN db_name NEW_VALUE dbname NOPRINT
SELECT name dbname FROM v\$database;
@?/rdbms/admin/catbundle_PSU_&dbname_ROLLBACK.sql
@?/rdbms/admin/utlrp.sql
set lines 168 pages 99
col action_time for a20
col action for a15
col namespace for a12
col version for a18
col id for 99999999
col bundle_series for a15
col comments for a28
prompt db version
select to_char(t1.action_time,‘yyyy-mm-dd hh24:mi:ss‘) action_time,t1.action,t1.namespace,t1.version,id,t1.bundle_series,t1.comments from dba_registry_history t1 order by t1.action_time;
prompt 
prompt comp info
col comp_name for a48
col comp_id for a12
col version for a16
col status for a12
col modified for a20
select t2.comp_id, t2.comp_name, t2.version, t2.status, to_char(to_date(t2.modified,‘dd-mm-yyyy hh24:mi:ss‘),‘yyyy-mm-dd hh24:mi:ss‘) modified from dba_registry t2 order by t2.modified,t2.comp_id;
quit;
EOF

1.5.2 opatch回滚补丁

cd ${PATCH_PATH}
opatch rollback -id 27870645

1.5.3 手动回滚补丁

# 1. 关闭DB服务
su - oracle
${ORACLE_HOME}/bin/srvctl stop home -o ${ORACLE_HOME} -s <status file location> -n <node name>

# 2. 关闭集群
su - root
. /home/grid/.bash_profile
${ORACLE_HOME}/crs/install/rootcrs.pl -unlock

# 3. 回滚补丁 GI HOME (可能需要 -ocmrf 选项)
su - grid
${ORACLE_HOME}/OPatch/opatch rollback -local -id <OCW Components_number> -oh ${ORACLE_HOME}

${ORACLE_HOME}/OPatch/opatch rollback -local -id <ACFS Components_number> -oh ${ORACLE_HOME}

${ORACLE_HOME}/OPatch/opatch rollback -local -id <DB_PSU_number> -oh ${ORACLE_HOME}

# 4. 回滚补丁 DB HOME
su - oracle
<UNZIPPED_PATCH_LOCATION>/<GI_PSU_number>/<OCW Components_number>/custom/server/<OCW Components_number>/custom/scripts/prepatch.sh -dbhome <ORACLE_HOME>

${ORACLE_HOME}/OPatch/opatch rollback -local -id <OCW Components_number> -oh ${ORACLE_HOME} 
${ORACLE_HOME}/OPatch/opatch rollback -local -id <DB_PSU_number> -oh ${ORACLE_HOME}

<UNZIPPED_PATCH_LOCATION>/<GI_PSU_number>/<OCW Components_number>/custom/server/<OCW Components_number>/custom/scripts/postpatch.sh -dbhome <ORACLE_HOME>

# 5. 启动集群服务
su - root
. /home/grid/.bash_profile
${ORACLE_HOME}/rdbms/install/rootadd_rdbms.sh
${ORACLE_HOME}/crs/install/rootcrs.pl -patch

# 6. 启动DB服务
su - oracle
${ORACLE_HOME}/bin/srvctl start home -o <ORACLE_HOME> -s <status file location> -n <node name>

1.5.4 更新数据字典

export dbid=$(echo ${ORACLE_SID} | tr ‘[a-z]‘ ‘[A-Z]‘)
sqlplus -S "/ as sysdba" <<EOF
-- SELECT ‘/ups/app/oracle/db11g/cfgtoollogs/catbundle/‘ || ‘catbundle_PSU_‘ || name || ‘_ROLLBACK_‘ || TO_CHAR(SYSDATE, ‘YYYYMonDD_hh24_mi_ss‘, ‘NLS_DATE_LANGUAGE=‘‘AMERICAN‘‘‘) || ‘.log‘ AS spool_file FROM v$database;
@?/rdbms/admin/catbundle_PSU_${dbid}_ROLLBACK.sql
@?/rdbms/admin/utlrp.sql
EOF

2. 常见问题及处理方案

2.1 在RAC中升级PSU(11.2.0.4.181016)后HAIP发生改变

1) 问题信息

在DB 实例的alert log中,发现升级补丁后重启实例时,提示gpnp获取HAIP的警告信息

2)解决方案

原因:在RAC环境中,OCW PSU未应用到DB ORACLE_HOME引起

# 方案1 应用OCW PSU 到DB HOME
su - oracle
export UNZIPPED_PATCH_LOCATION=‘/apps/soft/28429134‘
${UNZIPPED_PATCH_LOCATION}/27735020/custom/server/27735020/custom/scripts/prepatch.sh -dbhome ${ORACLE_HOME}
${ORACLE_HOME}/OPatch/opatch napply -oh ${ORACLE_HOME} -local ${UNZIPPED_PATCH_LOCATION}/27735020/custom/server/27735020
${UNZIPPED_PATCH_LOCATION}/27735020/custom/server/27735020/custom/scripts/postpatch.sh -dbhome ${ORACLE_HOME}

# 方案2 登录DB 实例并修改 cluster_interconnects 参数
alter system set cluster_interconnects=‘169.254.111.210‘ scope=spfile sid=‘orcl1‘;
alter system set cluster_interconnects=‘169.254.58.170‘ scope=spfile sid=‘orcl2‘;

3) 参考文档

11.2.0.4 RAC Database Instance Fails to Start with "No connectivity to other instances in the cluster during startup" After Applying 11.2.0.4 OCT 2018 DB PSU (11.2.0.4.181016 DB PSU) (Patch# 28204707) (文档 ID 2471441.1)

Oracle-11g升级PSU补丁

总结建议

在RAC环境中仅仅安装DB PSU累积补丁集的数据库器上依然存在此隐患。建议在RAC环境上升级GI PSU(gi home and db home都应用PSU补丁)

2.2 DB HOME二进制文件未应用问题

1)问题信息

部署RAC环境时,先应用GI PSU补丁后DBCA建库,出现DB HOME软件未能应用。

2)可能原因

  • 数据库服务器上有多个不同版本的GI 软件目录,GI补丁只会应用相同版本补丁到DB HOME

  • 在OCR中没有注册成功的数据库

    • 查找OCR中已注册DB HOME

      $GRID_HOME/bin/crsctl stat res -p -w "TYPE = ora.database.type" | egrep ‘^NAME|^ORACLE_HOME‘

3) 处理方案

# 重新运行 opatch auto 命令应用指定的软件目录
su - root
opatch auto <UNZIPPED_PATCH_LOCATION> -oh <RAC_HOME> -ocmrf <ocm response file>


# 检查确认
$GRID_HOME/bin/crsctl stat res -p -w "TYPE = ora.database.type" | egrep ‘^NAME|^ORACLE_HOME‘

Oracle-11g升级PSU补丁

上一篇:数据库三大范式


下一篇:sql中错误使用EXISTS语法