Home > Database > Mysql Tutorial > Oracle] Data Guard 之 浅析Switchover与Failover

Oracle] Data Guard 之 浅析Switchover与Failover

WBOY
Release: 2016-06-07 16:19:36
Original
1014 people have browsed it

以下是对Oracle中Switchover与Failover的使用进行了详细的分析介绍,需要的朋友参考下 Data Guard主从库之间的角色切换分为以下两种: 1)Switchover Swithchover通常都是人为的有计划的进行角色互换,比如升级等。它通常都是无损的,即不会有数据丢失。其执

以下是对Oracle中Switchover与Failover的使用进行了详细的分析介绍,需要的朋友参考下

 

Data Guard主从库之间的角色切换分为以下两种:
1)Switchover
Swithchover通常都是人为的有计划的进行角色互换,比如升级等。它通常都是无损的,即不会有数据丢失。其执行主要分为两个阶段:
1.Primary转为Standby
2.Standby(之一)转为Primary
2)Failover
Failover是指由于Primary故障无法短时间恢复,Standby不得不充当Primay的角色,如果处于最高性能模式,这种切换很有可能导致数据丢失。

下面分别演示物理Standby的Switchover和Failover(逻辑Standby的切换类似)。

1. 物理Standby执行Switchover
1) 确认pirmary是否可以切换为standby
PRIMARY>select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO STANDBY
2) 切换primary为standby
PRIMARY>alter database commit to switchover to physical standby;
3) 启动原primary到mount状态
此时原primary就是以standby身份在运行了。
4) 确认standby是否可以切换为primary
STANDBY>select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO PRIMARY
5) 切换standby为primary
STANDBY>alter database commit to switchover to primary;
Database altered.
STANDBY>alter database open;
Database altered.
6) 验证
PRIMARY>select database_role from v$database;
DATABASE_ROLE
----------------
PHYSICAL STANDBY
STANDBY>select database_role from v$database;
DATABASE_ROLE
----------------
PRIMARY
可以看到原来的primary现在变成standby,原来的standby变成primary了。
检查新的primary的log_archive_dest参数的设置是否正确:
STANDBY>show parameter log_archive_dest_2
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
log_archive_dest_2            string      service=O01DMS0 ARCH VALID_FOR
                                                              =(ONLINE_LOGFILES,PRIMARY_ROLE
                                                               ) DB_UNIQUE_NAME=O01DMS0
STANDBY>show parameter log_archive_dest_state_2
NAME                                 TYPE        VALUE
------------------------------------ ----------- ---------------------
log_archive_dest_state_2             string      ENABLE
在新primary端做log switch:
STANDBY>alter system switch logfile;
System altered.
STANDBY>select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
           479
在新standby端查看:
PRIMARY>select max(sequence#) from v$archived_log;
MAX(SEQUENCE#)
--------------
           479
两边的归档日志的最大序号吻合,说明switchover成功。

2. 物理Standby执行Failover
1). 检查standby归档文件是否连续
STANDBY>SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;
no rows selected
这一步很重要,,必须确保所有已生成的归档文件都已传到standby服务器。
如果上述语句有返回结果,则必须把缺失的归档文件从primary端复制到standby端,然后通过以下命令将其加入数据库:
STANDBY>alter database register physical logfile 'filespec'
2). 检查standby归档文件是否完整
STANDBY>SELECT UNIQUE THREAD# AS THREAD, MAX(SEQUENCE#) OVER (PARTITION BY threa
d#) AS LAST from V$ARCHIVED_LOG;
    THREAD       LAST
---------- ----------
         1        479
通过上述语句可以查出standby目前序号最大的归档日志为479,如果在primary端有比479更大的归档日志,把它们拷贝过来,然后通过以下命令将其加入数据库:
STANDBY>alter database register physical logfile 'filespec'
3)启动failover
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH FORCE;4)切换为primaryTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
ALTER DATABASE OPEN;STANDBY>select database_role from v$database;DATABASE_ROLE----------------PRIMARY

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template