1.环境介绍
主库(RAC)
IP地址:192.168.1.210,192.168.1.211
操作系统版本:ole5.8 64bit
数据库版本:11.2.0.4 64bit
数据库sid名:MECBS1,MECBS2
数据库主机名:node1,node2
数据库db_unique_name:MECBS
备库1 物理备库
IP地址:192.168.1.219
操作系统版本:ole5.8 64bit
数据库版本:11.2.0.4 64bit
数据库sid名:PHUB
数据库主机名:dataguard
数据库db_unique_name:PHUB
主库和备库均采用ASM管理
2.数据库的角色切换是DATA GUARD的价值所在,在升级的时候,在住数据库出现故障暂时无法恢复的时候需要进行主备数据库切换,以减少系统停机时间,在最高可用性架构中,DATA GUARD也是非常重要的组成部分,它能在RAC基础上进一步提高Oracle数据库的可用性。
Data Guard的切换分为两种:Switchover(正常切换)和Failover(异常切换)。在升级,服务器运维等计划停机的时候用到Switchover切换,根据不同数据保护模式,日志传输和应用情况,Failover切换可能会导致数据的丢失。
Switchover 切换(由RAC 主库切换成备库,单实例切换成主库):
如果standby数据库是一个RAC数据库,只保留一个节点实例运行,关闭其他节点实例。
1.主数据库执行操作
(1)停止集群的其他节点,保留节点一完成切换操作:
[oracle@node2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 11.2.0.4.0 Production on Sat Nov 15 15:18:40 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
(2)在节点一上执行以下sql,查询主数据库是否满足切换条件:
SQL> select switchover_status from gv$database;
SWITCHOVER_STATUS
--------------------
TO STANDBY
(3)如果上一步结果显示SESSIONS ACTIVE,在切换的时候可以指定with session shutdown子句强制关闭活动会话,在主库上执行以下语句执行切换操作:
SQL> alter database commit to switchover to physical standby;
Database altered.
(4)在新备库(RAC)上关闭数据库实例,启动数据库(所有节点)到日志应用模式:
SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 484356096 bytes
Fixed Size 2254464 bytes
Variable Size 264243584 bytes
Database Buffers 209715200 bytes
Redo Buffers 8142848 bytes
Database mounted.
SQL> alter database open;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
READ ONLY
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
主库已经成功切换成物理备库:
SQL> select open_mode ,database_role from gv$database;
OPEN_MODE DATABASE_ROLE
-------------------- ----------------
READ ONLY WITH APPLY PHYSICAL STANDBY
READ ONLY WITH APPLY PHYSICAL STANDBY
1.standby数据库执行操作:
1.执行以下SQL语句查询是否满足转换条件:
SQL> select switchover_status from gv$database;
SWITCHOVER_STATUS
--------------------
TO PRIMARY
2.执行以下SQL语句切换为主库:
SQL> alter database commit to switchover to primary;
Database altered.
SQL> select open_mode from v$database;
OPEN_MODE
--------------------
MOUNTED
3.打开数据库:
SQL> alter database open;
Database altered
SQL> select database_role from v$database;
DATABASE_ROLE
----------------
PRIMARY
如果Standby数据库是RAC数据库,那么只有一个实例能够运行MRP进程,其他实例只能运行RFS进程接收日志。
SQL> conn /as sysdba
Connected.
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination +RECO
Oldest online log sequence 153
Next log sequence to archive 0
Current log sequence 153
另一个节点:
SQL> archive log list;
Database log mode Archive Mode
Automatic archival Enabled
Archive destination +RECO
Oldest online log sequence 0
Next log sequence to archive 0
Current log sequence