oracle Data Guard 主备切换(Switchover和failover过程演示)

版权声明:原创手打 转载请注明来源 https://blog.csdn.net/qq_42774325/article/details/82666340

Oracle Data Guard 主备切换

Oracle Dataguard的角色转换包含两类:Switchover和Failover。Switchover指主备之间角色转换,主库降为备库,备库升级为主库。而failover则是指主库出现问题时,备库切换为主库。

 

下面为官方定义:

 

Switchover

 

Allows the primary database to switch roles with one of its standby databases.There is no data loss during a switchover.After a switchover,each database continues to participate in the Data Guard configuration with its new role.

 

Failover

 

Changes a standby database to the primary role in response to a primary database failure.If the primary database was not operating in either          maximum protection mode or maximum availability mode before the failure,some data loss may occur.If Flashback Database is enabled on the primary database,it can be reinstated as a standby for the new primary database once the reason for the failure is corrected.

扫描二维码关注公众号,回复: 3167647 查看本文章

switchover

过程演示

 

在主库:

select name,DATABASE_ROLE from v$database;

 

 

检查归档日志有没有中断:

select status, GAP_STATUS from v$archive_dest_status where dest_id=2;

 

 

查询切换前主库的状态,状态为TO STANDBY,主库才可以切换到备库:

select switchover_status from v$database;

 

 

切换当前主库为备库,切换完成后,数据库会被关闭:

alter database commit to switchover to physical standby;

 

 

启动数据库到mount状态,当前已经变成备库:

startup mount

 

 

查询切换状态,此时状态发生变化:

select switchover_status from v$database;

 

 

也可以查询此时数据库的角色,角色为:PHYSICAL STANDBY

select DATABASE_ROLE from v$database;

 

 

到备库:

查数据库的角色,在切换之前数据库的角色是:PHYSICAL STANDBY

select name,DATABASE_ROLE from v$database;

 

 

查询切换角色的状态,此时因为原来的主库已经切换到的备库,

则这个备库是可以切换到主库了,状态为:TO PRIMARY

select switchover_status from v$database;

 

 

切换备库到主库,一旦切换到主库,数据库此时为mount状态,

需要找开数据库:

alter database commit to switchover to primary;

 

 

alter database open;

 

 

再次验证数据库的角色,此时数据角色变成:PRIMARY

select name,DATABASE_ROLE from v$database;

 

 

在新的备库:

打开新的备库到只读:

alter database open;

 

 

在新的备库开启日志的应用:

alter database recover managed standby database using current logfile disconnect from session;

 

 

再次查询数据库的打开模式的时候,是:READ ONLY WITH APPLY

select open_mode from v$database;

 

 

主备切换完成,在新的主库做数据变更,在新的备库做数据校验,是否同步。

 

主库查看hr用户下的表a的数据

 

 

删除id为3的数据

 

 

commit;后强制切换日志

 

 

到备库查看

数据已同步

 

 

 

 

 

 

 

 

failover

过程演示

先查看主库的归档信息

 

 

把主库关闭,模拟为主库损坏

 

 

此时主库损坏,到备库操作

在备库确认是否有日志没有同步:

SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;

 

 

如果此查询有记录,需要把这些日志从主库拷贝到备库,并注册到数据库中:

ALTER DATABASE REGISTER PHYSICAL LOGFILE '拷贝过来的日志文件'; 

 

查询日志是否应用到最新状态:

select distinct thread#,max(sequence#) over(partition by thread#) a from v$archived_log;

 

 

在备库做失败切换:

alter database recover managed standby database finish force; 

 

 

alter database commit to switchover to primary; 

 

 

alter database open; 

 

 

此时不再是dataguard环境了,需要根据现有的主库搭建一个新的dataguard环境;

猜你喜欢

转载自blog.csdn.net/qq_42774325/article/details/82666340