一、环境准备
database | os |
11.2.0.4 x64 | CentOS Linux release 7.7.1908 (Core) |
二、补丁工具准备
OPatch | DB PSU |
p6880880_112000_Linux-x86-64.zip | p31537677_112040_Linux-x86-64 |
三、准备工作
1、 查看组件信息
SQL> set linesize 500 pagesize 600
SQL> col COMP_NAME for a30
SQL> select COMP_ID,COMP_NAME,VERSION,STATUS from DBA_REGISTRY;
2、查看补丁情况
SQL> set linesize 500 pagesize 600
SQL> col ACTION_TIME for a30
SQL> col COMMENTS for a30
SQL> select ACTION_TIME, ACTION,version, COMMENTS from sys.DBA_REGISTRY_HISTORY;
3、查看无效对象
SQL>select count(*) from dba_objects where status<>'VALID';
四、开始打补丁
1、更新OPatch版本
(1) 上传p6880880_112000_Linux-x86-64.zip到/home/oracle/opatch目录下, /home/oracle/opatch给777权限。
[oracle@myoracledemo ~]$ mkdir opatch
[oracle@myoracledemo ~]$ cd /home/oracle/opatch
[root@myoracledemo ~]# cd /home/oracle/opatch/
[root@myoracledemo opatch]# chown -R oracle.oinstall /home/oracle/opatch/
(2) root用户下将原OPatch目录改名。
[oracle@myoracledemo ~]$ mv $ORACLE_HOME/OPatch $ORACLE_HOME/OPatch.bak
2、oracle目录OPatch替换
[oracle@myoracledemo ~]$cd /home/oracle/opatch/
[oracle@myoracledemo ~]$unzip p6880880_112000_Linux-x86-64.zip
[oracle@myoracledemo ~]$unzip p31537677_112040_Linux-x86-64.zip
[oracle@myoracledemo opatch]$ mv OPatch /u01/app/oracle/product/11.2.0/db_1
[oracle@myoracledemo opatch]$ /u01/app/oracle/product/11.2.0/db_1/OPatch/opatch --verison
3、 测试兼容性
[oracle@myoracledemo opatch]$ $ORACLE_HOME/OPatch/opatch prereq CheckConflictAgainstOHWithDetail -phBaseDir /home/oracle/opatch/31537677 -oh $ORACLE_HOME
4、 为数据库做冷备份
[oracle@myoracledemo opatch]$ rman target /
RMAN> run {
shutdown immediate;
startup mount;
allocate channel c1 type disk;
allocate channel c2 type disk;
backup full tag='db_full_bak' database format '/home/oracle/rmanbak/full_cold_%d_%s.bak';
alter database open;
}
然后使用root用户备份oracle_home (将#ORACLE_HOME上级目录整个备份)
[oracle@myoracledemo opatch]$tar -zcvpf db_bak.tar.gz /u01/app/oracle/product/11.2.0
5、 关闭数据库实例及相关进程 (静态监听、动态监听、EOM、相关服务)
—停止数据库外部进程
[root@myoracledemo ~]# ps -ef|grep -v grep |grep LOCAL=NO|awk '{print $2}'|xargs kill -9
SQL> shutdown immediate;
[oracle@myoracledemo 11.2.0]$ lsnrctl stop
[oracle@myoracledemo 11.2.0]$ lsnrctl status
[oracle@myoracledemo 11.2.0]$ ps -ef |grep ora_|grep -v grep
[oracle@myoracledemo 11.2.0]$ netstat -an |grep 1521
[oracle@myoracledemo 11.2.0]$ netstat -an |grep 1158
6、给oracle database补丁
[root@myoracledemo ~]# yum install -y psmisc* #centos需要安装这个依赖包
[oracle@myoracledemo 11.2.0]$ $ORACLE_HOME/OPatch/opatch napply -oh $ORACLE_HOME -local /home/oracle/opatch/31537677
7、查看打补丁情况
[oracle@myoracledemo db_1]$ /u01/app/oracle/product/11.2.0/db_1/OPatch/opatch lsinv
8、升级数据库数据字典、编译无效对象
数据库启动,并加载修改SQL Files到数据库
SQL> startup
升级数据库数据字典
SQL> @?/rdbms/admin/catbundle.sql psu apply
编译无效对象的脚本
SQL>@?/rdbms/admin/utlrp.sql
9、查看 PSU 更新信息
SQL>set line 150
SQL>col ACTION_TIME for a30
SQL>col ACTION for a8
SQL>col NAMESPACE for a8
SQL>col VERSION for a10
SQL>col BUNDLE_SERIES for a5
SQL>col COMMENTS for a20
SQL>select * from dba_registry_history;
SQL> select count(*) from dba_objects where status<>'VALID';
查看监听的情况,启动监听
[oracle@myoracledemo db_1]$ lsnrctl start