Oracle Dataguard之switchover
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.
在生产环境中,用的较多的是最大可用模式。为了进行后续的实验,我们将默认的最大性能模式转换为最大可用模式。
一、 转换模式
1> 在主库上查询当前数据的保护模式 -->> node1 上操作
SQL> select protection_mode from v$database;
PROTECTION_MODE
--------------------
MAXIMUM PERFORMANCE
2> 在主库上转换模式
SQL> alter database set standby database to maximize availability;
二、 主库环境准备 -->> node1 上操作
1> 添加standby redo log
[oracle@node1 ~]$ mkdir /u01/standby
SQL> alter database add standby logfile '/u01/standby/standby01.log' size 50M;
SQL> alter database add standby logfile '/u01/standby/standby02.log' size 50M;
SQL> alter database add standby logfile '/u01/standby/standby03.log' size 50M;
SQL> alter database add standby logfile '/u01/standby/standby04.log' size 50M;
2> 修改主库的配置参数
SQL> alter system set log_archive_dest_1='location=USE_DB_RECOVERY_FILE_DEST valid_for=(all_logfiles,all_roles) db_unique_name=orcl';
-->> 原来的参数是valid_for=(online_logfiles,primary_role),现修改为(all_logfiles,all_roles),代表在主库降为备库角色时,该地址也可作为standby redo log 的归档地址
SQL> alter system set fal_server=to_victor;
SQL> alter system set db_file_name_convert='victor','orcl' scope=spfile;
SQL> alter system set log_file_name_convert='victor','orcl' scope=spfile;
SQL> alter system set standby_file_management='auto';
三、备库环境准备 -->> node2 上操作
SQL> alter system set log_archive_dest_1='location=/u01/archivelog valid_for=(all_logfiles,all_roles) db_unique_name=victor';
-->> 原来的参数是valid_for=(standby_logfiles,standby_role),现改为(all_logfiles,all_roles),即当node2升为主库时,该地址也可作为online redo log的归档 地址
SQL> alter system set log_archive_dest_2='service=to_orcl lgwr affirm sync valid_for=(online_logfiles,primary_role) db_unique_name=orcl';
SQL> alter system set log_archive_dest_state_2='enable';
四、 校验主备之间是否有日志传输错误或者redo gap
1> 主库上查询 -->> node1 上操作
SQL> select status,gap_status from v$archive_dest_status where dest_id=2;
STATUS GAP_STATUS
-------- ------------------------
VALID NO GAP
status代表日志传输的状态,gap_status代表主备归档日志是否有gap
注意:status必须为valid且gap_status必须为no gap
2> 备库上查询 -->> node2上操作
在日志传输ok且没有日志gap的情况下,看日志是够被应用
SQL> select sequence#,applied from v$archived_log;
五、 查询主备的switchover状态
1> 主库上查询
SQL> select switchover_status,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------
TO STANDBY PRIMARY
2> 备库上查询
SQL> select switchover_status,database_role from v$database;
SWITCHOVER_STATUS DATABASE_ROLE
-------------------- ----------------
NOT ALLOWED PHYSICAL STANDBY
六、 开始switchover
1> 主库切换到standby角色 -->> node1 上操作
SQL> alter database commit to switchover to physical standby with session shutdown;
SQL> shutdown immediate
SQL> startup
2> 备库上查询switchover的状态
SQL> select switchover_status from v$database;
SWITCHOVER_STATUS
--------------------
TO PRIMARY
-->> To Primary代表The database is ready to switch to the primary role
3> 备库切换到primary的角色 -->> node2 上操作
SQL> alter database commit to switchover to primary with session shutdown;
SQL> alter database open;
4> node1(原主库)上启用redo apply
SQL> alter database recover managed standby database using current logfile disconnect from session;
七、 查看switchover后主备状态
1> node1 上操作
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PHYSICAL STANDBY NOT ALLOWED
2> node2 上操作
SQL> select database_role,switchover_status from v$database;
DATABASE_ROLE SWITCHOVER_STATUS
---------------- --------------------
PRIMARY TO STANDBY
八、 测试
见前几篇测试方法
至此,主备switchover OK!
总结:
1> 官档上还是有点bug的,在执行switchover之前,它建议将备库关掉,启动到mount状态。如果是这样的话,当node1执行完switchover to physical standby的命令后,node2的switchover_status是SWITCHOVER PENDING,this status indicates that a switchover request has been received from the primary database and is being processed. A physical standby database cannot switch to the primary role while in this transient state.此时,无论是重启主库还是备库,node2的switchover_status始终是SWITCHOVER PENDING,这时在备库上应用redo apply即可解决问题,即执行 alter database recover managed standby database using current logfile disconnect from session即可
2> 关于switchover_status的参数说明,官档如下


Oracle Dataguard之switchover的更多相关文章
- Oracle Dataguard之failover
Oracle Dataguard中,角色转换包含两类:Switchover和Failover.上文<Oracle Dataguard之switchover>中,我们已经谈过了switcho ...
- [Oracle] DataGuard switchover
Oracle DataGuard switchover 2013/07/11 Tag.Data Guard,primary,standby,switchover 切换前primary site和sta ...
- Oracle DataGuard主备切换(switchover)
Oracle DataGuard主备切换可以使用传统的手动命令切换,也可以使用dgmgr切换,本文记录手动切换. (一)将主库切换为物理备库 STEP1:查看主库状态 SQL> SELECT O ...
- Oracle Dataguard之物理standby的基本配置
尽管网上有很多Oracle Dataguard的配置教程,但不难发现,很多采用的是rman duplicate这种方法,尽管此种方法较为简便.但在某种程度上,却也误导了初学者,虽说也能配置成功,但只知 ...
- Oracle dataguard 正常切换和应急切换
oracle dataguard提供异地容灾方案,能有效的防止单点故障和提供高可用技术,这里介绍dataguard正常主备切换和应急切换(应急切换模拟主库出现问题无法还原,备库脱离dataguard接 ...
- oracle dataguard主从切换
前言: 众所周知DataGuard一般的切换分成两种,一种是系统正常的情况下的切换这种方式为:switchover是无损切换,不会丢失数据:另外一种方式属于灾难情况下的切换,这种情况下一般主库已经启动 ...
- Oracle dataguard failover 实战
Oracle dataguard failover 实战 操作步骤 备库: SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINIS ...
- Oracle Dataguard故障转移(failover)操作
注意:故障转移会破坏DG的主从关系,使其变为互不相关的2个数据库,谨慎使用. (一)故障转移操作流程图 (二)故障转移操作流程 备注:以下操作步骤与上面流程图步骤一一对应 STEP1:刷新所有未发送到 ...
- Oracle DataGuard故障转移(failover)后使用RMAN还原失败的主库
(一)DG故障转移后切换为备库的方法 在DG执行故障转移之后,主库与从库的关系就被破坏了.这个时候如果要恢复主从关系,可以使用下面的3种方法: 将失败的主库重新搭建为备库,该方法比较耗时: 使用数据库 ...
随机推荐
- delphi 屏幕截屏
function GetScreenAll: TBitmap; // 截取全屏 var C: TCanvas; begin C := TCanvas.Create; result := TBitmap ...
- (原创)古典主义——平凡之美 佳作欣赏(摄影,欣赏)
文中图片摘自腾讯文化网:www.cal.qq.com 1.Abstract 生活本就是平淡的,如同真理一般寂静.平时生活中不经意的瞬间,也有它本来的美丽.下面一组图是上上个世纪到上个世纪末一个 ...
- Python之*args,**kw
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #021ca1; background-color: #8e352 ...
- ps(process status)
1.PS ps -a(all):显示现行终端机下的所有进程,包括其他用户的进程: ps -ax: 同时加上x参数会显示没有控制终端的进程. ps -j:显示与作业有关的信息:会话ID.进程组ID等 ...
- sql常见的面试题
1.用一条SQL语句 查询出每门课都大于80分的学生姓名 name kecheng fenshu 张三 语文 81张三 数学 75李四 语文 ...
- IOS 获取当前对象所在的VC
id next = [self nextResponder] ; while (next != nil) { next = [next nextResponder]; if ([next isKind ...
- SQLServer内核架构剖析 (转载)
SQL Server内核架构剖析 (转载) 这篇文章在我电脑里好长时间了,今天不小心给翻出来了,觉得写得很不错,因此贴出来共享. 不得不承认的是,一个优秀的软件是一步一步脚踏实地积累起来的,众多优秀的 ...
- ASP.NET 4.5.256 has not been registered on the Web server. You need to manually configure your Web server for ASP.NET 4.5.256 in order for your site to run correctly
Microsoft .NET Framework 4.6安装后,用户可能会在使用Microsoft Visual Studio 创建(或打开现有项目时)网站.或Windows Azure项目时遇到下面 ...
- Yii2 使用Composer
composer 是 PHP 用来管理依赖(dependency)关系的工具.你可以在自己的项目中声明所依赖的外部工具库(libraries),Composer 会帮你安装这些依赖的库文件 compo ...
- Ubuntu Server 15.04的安装
U盘启动工具的制作就跟Windows系统以及Linux各版本的desktop版不同,用的工具也是我第一次见到的“Win32_Disk_Imager”(点击下载) 安装过程请参考:http://www. ...