码迷,mamicode.com
首页 > 数据库 > 详细

如何利用闪回数据库特性恢复failover 后的dataguard 环境?

时间:2015-04-23 21:48:18      阅读:351      评论:0      收藏:0      [点我收藏+]

标签:

11g dataguard standby 切成主库,测试完成后恢复为原standby 环境


#######################
概述:
11204 单机对单机实施dg,因局方要求需要(读写模式)打开standby ;而这时原生产环境不能有任何影响动,依然对外服务;
采用的思路是:standby 直接failover 为primary db;这时原有dg关系被破坏,互不影响;


#######################
思路概要:
1.确认主库归档日志存放空间是否足够?(需考虑归档保留删除策略?);关闭主库到备库的日志传输
2.备库确认是否开启flashback database,以及闪回日志存放空间是否充足?
3.备库failover to primary (切换前确认是否日志延迟传输?手工注册)
4.业务测试
5.恢复failover 备库
6.确认dg 环境恢复是否正常(日志自动传输和应用?)?



#######################
具体实施步骤:

------主库defer 日志传输
alter system set log_archive_dest_2=defer;

---enable 日志传输:
alter system set log_archive_dest_2=enable;

-----备库(mount)配置 flashback database:
STANDBY DATABASE: Stop redo apply, configure flashback retention, 
start flashback database, open the database and start redo apply (Is active DG).

---检查备库是否启用flashback database:
select flashback_on from v$database;


注意这里需要确认下备库打开模式: mount?readonly with apply?
在11g 环境下备库可能启用了 ADG 特性 备库日志处于实时应用,数据库模式为 readonly with apply
这时需要重启数据库到mount状态修改flashback database 模式;


如果备库处于mount 状态,可以先取消日志apply ,直接打开闪回数据库特性;


---取消备库日志应用:
  ALTER DATABASE RECOVER MANAGED STANDBY DATABASE CANCEL;


---需要配置一下两个参数来打开flashback database 特性:
  ALTER SYSTEM SET db_recover_file_dest=‘/lixora/lixora/lixora/‘;
  ALTER SYSTEM SET db_recover_file_dest_size=100G;

  ALTER SYSTEM SET DB_FLASHBACK_RETENTION_TARGET=240;   ---4hours
  ALTER DATABASE FLASHBACK ON;
  
--手工创建还原点(该步骤没有测试过):
Creating Restore point in Physical Standby:
CREATE RESTORE POINT before_damage GUARANTEE FLASHBACK DATABASE


-------备库failover to primary db 应急切换步骤:
(注:模拟主库由于故障无法正常switchover,需要执行failover,强制备库->pridb并接管业务)

1.备库:
由于是failover,所以理解主库这时候已经无法正常使用,只需备库切换至pridb

【前提主库还是可用的:可选】查询没有应用的日志: 
 SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP; 

select distinct thread#,max(sequence#) over(partition by thread#) a from v$archived_log;
该语句取得当前数据库各线程已归档文件最大序号,如果primary 与standby 最大序号不相同,
必须将多出的序号对应的归档文件复制到待转换的standby服务器。


Cp过来并register 
  ALTER DATABASE REGISTER PHYSICAL LOGFILE ‘filespec1‘

停止应用恢复模式
alter database recover managed standby database finish;
or
ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH FORCE; 

转换standbydb为primary db
alter database commit to switchover to primary;


重启数据库,恢复正常业务
alter database open;


数据库角色查看:
select open_mode,database_role from v$database;
OPEN_MODE       DATABASE_ROLE
----------      ----------------
OPEN            PRIMARY


------恢复failover 的备库:
C. Using SQL*PLUS 
Step 1 Determine the Standby Became Primary SCN. 
Step 2 Flashback the Failed Primary Database. 
Step 3 Convert to physical standby database. 
Step 4 Restart Redo Transport. 
Step 5 Start Redo Apply. 


Step 1 Determine the SCN at which the old standby database became the primary database. 
SQL> SELECT TO_CHAR(STANDBY_BECAME_PRIMARY_SCN) FROM V$DATABASE;


Step 2 Flashback the Failed Primary Database to SCN standby_became_primary_scn.
SQL> SHUTDOWN IMMEDIATE; 
SQL> startup mount 
SQL> FLASHBACK DATABASE TO SCN <standby_became_primary_scn of step 1>;

Step 3 Convert the database to a physical standby database and Restart database in mount stage. 
SQL> ALTER DATABASE CONVERT TO PHYSICAL STANDBY; 
SQL> SHUTDOWN IMMEDIATE; 
SQL> STARTUP MOUNT;


Step 4 Restart Redo Transport to the New Physical Standby Database. 
1. If you have not set the remote archive destination on current primary then set remote archive destination:
SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_2 = ‘SERVICE=lixora VALID_FOR=(ONLINE_LOGFILES,PRIMARY_ROLE) DB_UNIQUE_NAME=lixora‘ SCOPE=BOTH;

2. Enable the destination 
SQL>ALTER SYSTEM SET LOG_ARCHIVE_DEST_STATE_2=ENABLE;

3. Perform a log switch to ensure that standby database begins receiving redo data from the new primary database 
SQL> ALTER SYSTEM SWITCH LOGFILE; 
SQL> SELECT DEST_ID, STATUS, ERROR FROM V$ARCHIVE_DEST WHERE DEST_ID=2;


--确认日志是否都apply了?
select applied from v$archived_log;

select message from v$dataguard_status;


Step 5 Start Redo Apply. 
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE DISCONNECT FROM SESSION;
Please see also fallowing docu:


TIPS:
Oracle? Data Guard Concepts and Administration
11g Release 2 (11.2)
13.2 Converting a Failed Primary Into a Standby Database Using Flashback Database

如何利用闪回数据库特性恢复failover 后的dataguard 环境?

标签:

原文地址:http://blog.csdn.net/lixora/article/details/45226895

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!