Dataguard中的role transition:switchover和failover以及将failover后的old primary flackback成physical standby库
Dataguard中的role transition包括两种:switchover和failover,
区别在于:switchover将一个physical standby database switchover成为primary database过程可以保证无数据丢失,在完成后其它的standby数据库和原来的primary库还可以成为这个dataguard的standby role的一部分.
Failover当主库crash无法正常启动时,将一个standby库failover成primary role库,如果在primary库在出故障之前不是处于protection的话,将会有一些数据丢失,因为当前在写的 redo没有办法传到standby库。如果primary,standby库都打开了flashback的话,可以将原来的主库重新设为新primary role数据库的standby库。
在进行role transition要检查:
primary,standby是否处于archvielog模式。
Standby库的tempory file要和primary匹配
是rac的话:在standby RAC上只有一个实例mount,其它都要关闭
COLUMN NAME FORMAT A18
COLUMN VALUE FORMAT A16
COLUMN TIME_COMPUTED FORMAT A24
SELECT * FROM V$DATAGUARD_STATS;---可以从这张视图看到没有应用的日志应用上去要多长时间
SQL> SELECT * FROM V$DATAGUARD_STATS; NAME VALUE UNIT TIME_COMPUTED ------------------ ---------------- ------------------------------ ------------------------ apply finish time +00 00:38:57.2 day(2) to second(1) interval 26-SEP-2008 23:16:39 apply lag +00 09:48:00 day(2) to second(0) interval 26-SEP-2008 23:16:39 estimated startup 25 second 26-SEP-2008 23:16:39 time standby has been o N 26-SEP-2008 23:16:39 pen transport lag +00 00:00:00 day(2) to second(0) interval 26-SEP-2008 23:16:39 SQL> select NAME ,DB_UNIQUE_NAME ,open_mode,DATABASE_ROLE from v$database; |
一.Switchovers的过程:
1. 检查主库目前的状态:
SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE;
SWITCHOVER_STATUS
--------------------
TO STANDBY
2.将主库置为standby role
SQL> alter database commit to switchover to physical standby; Database altered. SQL> shutdown immediate; ORA-01507: database not mounted ORACLE instance shut down. SQL> startup mount; ORACLE instance started. Total System Global Area 218103808 bytes Fixed Size 1260984 bytes Variable Size 117441096 bytes Database Buffers 96468992 bytes Redo Buffers 2932736 bytes Database mounted. |
2. standby库转为primary
SQL> select NAME ,DB_UNIQUE_NAME ,open_mode,DATABASE_ROLE from v$database; SQL> SELECT SWITCHOVER_STATUS FROM V$DATABASE; SWITCHOVER_STATUS -------------------- TO PRIMARY SQL> alter database commit to switchover to primary; Database altered. SQL> alter database open; Database altered. SQL> select NAME ,DB_UNIQUE_NAME ,open_mode,DATABASE_ROLE from v$database; NAME DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE ------------------ ------------------------------ ---------- ---------------- MAINDB standb READ WRITE PRIMARY |
主库上:
SQL> alter database recover managed standby database disconnect from session; Database altered. SQL> select NAME ,DB_UNIQUE_NAME ,open_mode,DATABASE_ROLE from v$database; NAME DB_UNIQUE_NAME OPEN_MODE DATABASE_ROLE ------------------ ------------------------------ ---------- ---------------- MAINDB maindb MOUNTED PHYSICAL STANDBY |
二.Failovers的过程:
查询没有应用的日志:
SQL> SELECT THREAD#, LOW_SEQUENCE#, HIGH_SEQUENCE# FROM V$ARCHIVE_GAP;
THREAD# LOW_SEQUENCE# HIGH_SEQUENCE#
Cp过来并register
SQL> ALTER DATABASE REGISTER PHYSICAL LOGFILE 'filespec1';
SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE FINISH FORCE;
SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PRIMARY;
SQL> ALTER DATABASE OPEN;
一旦主数据故障无法使用,就可以迅速激活镜像备份:
1、如果可能,归档主服务器当前重做日志,传送到镜像服务器;
2、使用主服务器的归档日志文件做恢复:
SQL>recover standby database;
3、激活并打开数据库:
SQL>alter database activate standby database; SQL>alter database mount; SQL>alter database open; |
三.将Failover之后的老的主库 flashback成新primary的standby库:
1. 在新主库查出failover时的SCN:
SQL> SELECT TO_CHAR(STANDBY_BECAME_PRIMARY_SCN) FROM V$DATABASE; TO_CHAR(STANDBY_BECAME_PRIMARY_SCN) ---------------------------------------- 172313 |
2. 在old primary库上:
SQL> SHUTDOWN IMMEDIATE; SQL> STARTUP MOUNT; SQL> FLASHBACK DATABASE TO SCN172313; SQL> ALTER DATABASE CONVERT TO PHYSICAL STANDBY; SQL> SHUTDOWN IMMEDIATE; SQL> STARTUP MOUNT; SQL> ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE DISCONNECT; |
blog