FAILOVER 切换
1. 查询备库角色及状态( AB 机)
SQL> col db_unique_name for a15
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;
DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------------- -------------------- ---------------- --------------------
db02 READ ONLY WITH APPLY PHYSICAL STANDBY NOT ALLOWED
2. 主机模拟故障关机( A 机)
SQL> shutdown abort
ORACLE instance shut down.
3. 检测备库归档日志是否有 GAP ( B 机)
SQL> select thread#,low_sequence#,high_sequence# from v$archive_gap;
no rows selected
没有明显的 GAP 现象,说明此次 FAILOVER 不会有数据丢失的现象。在 standby 端,要进行关闭 apply 和结束应用动作。
4. 备库进行关闭 apply 和结束 apply 动作( B 机)
SQL> alter database recover managed standby database cancel;
SQL> alter database recover managed standby database finish;
5. 备库进行切换( B 机)
SQL> alter database commit to switchover to primary with session shutdown;
6. 开启备库( B 机)
SQL> alter database open;
7. 查看备库角色( B 机)
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;
DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------------- -------------------- ---------------- --------------------
db02 READ WRITE PRIMARY RESOLVABLE GAP
此时 FAILOVER 切换完成
FAILOVER 还原
复制 数据库
1. A 库 开启到 nomount 模式 ( A 机)
SQL > startup nomount;
2. RMAN 进行 复制 ( B 机)
[ oracle@primary ~ ]$ rman target sys/oracle@db02 auxiliary sys/oracle@db0 1
RMAN>duplicate target database for standby nofilenamecheck from active database;
3. A 机开启实时应用( A 机)
SQL> alter database recover managed standby database using current logfile disconnect from session;
SQL> alter database open read only;
Database altered.
SQL> alter database recover managed standby database using current logfile disconnect from session;
Database altered.
4. 查看 AB 机状态
( A 机)
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;
DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------------- -------------------- ---------------- --------------------
db01 READ ONLY WITH APPLY PHYSICAL STANDBY RECOVERY NEEDED
( B 机)
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;
DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------------- -------------------- ---------------- --------------------
db02 READ WRITE PRIMARY SESSIONS ACTIVE
AB 库切换
(1) 新 主库操作( B 机 )
SQL> alter database commit to switchover to physical standby with session shutdown;
Database altered.
SQL> startup mount;
ORACLE instance started.
Total System Global Area 1.3429E+10 bytes
Fixed Size 2265944 bytes
Variable Size 6878661800 bytes
Database Buffers 6543114240 bytes
Redo Buffers 4612096 bytes
Database mounted.
(2) 新 备库 操作( A 机)
SQL> alter database commit to switchover to primary with session shutdown;
Database altered.
SQL> alter database open;
Database altered.
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;
DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------------- -------------------- ---------------- --------------------
Db01 READ WRITE PRIMARY RESOLVABLE GAP
( 3 ) B 机 操作
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;
DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
-------------------- -------------------- ---------------- --------------------
Db02 MOUNTED PHYSICAL STANDBY NOT ALLOWED
( 4 )打开备库开启实时同步( B 机)
SQL> alter database open read only;
Database altered.
SQL> alter database recover managed standby database using current logfile disconnect;
Database altered.
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;
DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STAT
--------------- ---------- ---------------- ---------------
Db02 READ ONLY PHYSICAL STANDBY NOT ALLOWED
WITH APPLY
( 5 )再次查看 A 机( A 机)
SQL> select db_unique_name,open_mode,database_role,switchover_status from v$database;
DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE SWITCHOVER_STATUS
--------------- -------------------- ---------------- --------------------
Db01 READ WRITE PRIMARY TO STANDBY
此时 ,已经切换回最初的状态
---------- end ----------
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31529886/viewspace-2284245/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31529886/viewspace-2284245/