一、备库操作
1.关闭备库数据库实例
sqlplus / as sysdba
startup
shutdown immediate
# 查看oracle进程
ps -ef | grep sqlplus
2.关闭监听
lsnrctl start
lsnrctl stop
lsnrctl status
3.升级Opatch
# 备份当前Opatch目录
su - oracle
cd $ORACLE_HOME
mv OPatch OPatch14.bak
4.解压6880880_190000_Linux-x86-64.zip
cd /soft
ls
unzip -d $ORACLE_HOME p6880880_190000_Linux-x86-64.zip
# 解压完查看OPatch版本
cd $ORACLE_HOME/OPatch
./opatch version
5.解压和应用33806152补丁
cd /soft
ls
unzip p35943157_190000_Linux-x86-64.zip
su - root
cd /soft
chown oracle:oinstall p35943157_190000_Linux-x86-64.zip
6.检查补丁是否冲突
cd 35943157
$ORACLE_HOME/OPatch/opatch prereq CheckConflictAgainstOHWithDetail
7.应用补丁
$ORACLE_HOME/OPatch/opatch apply
查看是否应用成功
cd $ORACLE_HOME/OPatch
./opatch lspatches
二、主库操作
1.备份oracle文件
cd $ORACLE_HOME
cd ..
ls
tar -cvzf db_home.tar.gz db_1/
2.主库关闭数据库及监听程序
sqlplus / as sysdba
shutdown immediate
exit
ps -ef |grep sqlplus
**##关闭监听**
lsnrctl start
lsnrctl stop
lsnrctl status
3.升级OPatch
##拷贝当前Opatch目录
su - oracle
cd $ORACLE_HOME
mv OPatch OPatch14.bak
# 解压p6880880_190000_Linux-x86-64.zip安装包
cd /soft
ls
unzip -d $ORACLE_HOME p6880880_190000_Linux-x86-64.zip
# 查看OPatch版本
cd $ORACLE_HOME/OPatch
./opatch version
4.应用补丁
# 解压补丁包
cd /soft
ls
unzip p35943157_190000_Linux-x86-64.zip
cd 35943157
$ORACLE_HOME/OPatch/opatch prereq CheckConflictAgainstOHWithDetail
$ORACLE_HOME/OPatch/opatch apply
cd $ORACLE_HOME/OPatch
./opatch lspatches
5.注册前检查
cd $ORACLE_HOME/OPatch
lsnrctl start
sqlplus / as sysdba
startup upgrade
[oracle@ora19 OPatch]$ ./datapatch -prereq
6.检查完成注册补丁
./datapatch -verbose
7.编译无效对象
cd $ORACLE_HOME//rdbms/admin
$ sqlplus / as sysdba
SQL> @utlrp.sql
8.检查主库补丁注册情况
select VERSION,VERSION_FULL from dba_registry;
9.备库切换主库完成补丁注册
1、主库
SQL> select name,open_mode,switchover_status from v$database;
NAME OPEN_MODE SWITCHOVER_STATUS
--------- -------------------- --------------------
PROD1 READ WRITE TO STANDBY
SQL> alter system switch logfile;
System altered.
SQL> alter system archive log current;
System altered.
SQL> alter database commit to switchover to physical standby with session shutdown;
Database altered.
SQL> shutdown abort
ORACLE instance shut down.
SQL> startup mount
ORACLE instance started.
Total System Global Area 849530880 bytes
Fixed Size 1348244 bytes
Variable Size 511708524 bytes
Database Buffers 331350016 bytes
Redo Buffers 5124096 bytes
Database mounted.
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
RECOVERY NEEDED
SQL> alter database open;
Database altered.
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO PRIMARY
2、备库
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Database altered.
SQL> alter database commit to switchover to primary;
Database altered.
SQL> select name,DATABASE_ROLE from v$database;
NAME DATABASE_ROLE
--------- ----------------
RUIADG PRIMARY
SQL> alter database open;
Database altered.
SQL> select name,open_mode,switchover_status from v$database;
NAME OPEN_MODE SWITCHOVER_STATUS
--------- -------------------- --------------------
PROD1 READ WRITE TO STANDBY
3、新备库(原主库)启用实时日志应用
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
SQL> select name,open_mode,switchover_status from v$database;
NAME OPEN_MODE SWITCHOVER_STATUS
--------- -------------------- --------------------
RMANPRI READ ONLY RECOVERY NEEDED
4、新主库切换日志
SQL> alter system switch logfile;
System altered.
5、分别查看当前主备库切换后当前日志序列号
主库:
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle/archive
Oldest online log sequence 52
Next log sequence to archive 54
Current log sequence 54
备库:
SQL> archive log list
Database log mode Archive Mode
Automatic archival Enabled
Archive destination /oracle/archive
Oldest online log sequence 53
Next log sequence to archive 0
Current log sequence 54
6、查看当前主备库状态
主库:
SQL> select name,open_mode,switchover_status from v$database;
NAME OPEN_MODE SWITCHOVER_STATUS
--------- -------------------- --------------------
RMANPRI READ WRITE TO STANDBY
备库:
SQL> select name,open_mode,switchover_status from v$database;
NAME OPEN_MODE SWITCHOVER_STATUS
--------- -------------------- --------------------
RMANPRI READ ONLY WITH APPLY NOT ALLOWED
三、回退补丁
sqlplus / as sysdba
startup
shutdown immediate
exit
# 关闭监听
lsnrctl start
lsnrctl stop
lsnrctl status
# 回退补丁
cd $ORACLE_HOME/OPatch
./opatch lspatches
./opatch rollback -id 35943157