10g_dataguard_failover

oracle_mao發表於2012-05-11

大體步驟:
1、啟動failover
SQL> alter database recover managed standby database finish force;

FORCE 關鍵字將會停止當前活動的RFS 程式,以便立刻執行failover。
剩下的步驟就與前面switchover 很相似了

2、切換物理standby 角色為primary
SQL> alter database commit to switchover to primary;

3、啟動新的primary 資料庫。
SQL> alter database open;

這樣就可以了,不需要在主庫上做啥操作。

如果想再將已經切換的系統變回原形,那就需要重新配置dg,因為在failover之後,原來的主庫就不是dg的一部分了。如果重新配置dg,那就要以原來的備庫(現在的主庫)作為主庫了,因為他在後續有很多操作了已經(無論是測試還是真正的火災他必定是已經當了很久的主庫了),待重新配置完dg之後,再做一次switchover切換,就可以將dg完完全全的恢復到我們所有測試之前的角色模式了。

實驗:
環境:
主庫:150-----因為是failover,所以在切換角色時150不需要做任何操作
備庫:200
1、200上:
SQL> alter database recover managed standby database finish force;
SQL> alter database commit to switchover to primary;
SQL> alter database open;
SQL> select switchover_status from v$database;
 
2、此時檢視原來的主庫150的狀態
 
解析:如果想再將已經切換的系統變回原形,那就需要重新配置dg,因為在failover之後,原來的主庫就不是dg的一部分了。如果重新配置dg,那就要以原來的備庫(現在的主庫)作為主庫了,因為他在後續有很多操作了已經(無論是測試還是真正的火災他必定是已經當了很久的主庫了),待重新配置完dg之後,再做一次switchover切換,就可以將dg完完全全的恢復到我們所有測試之前的角色模式了

3、重新配置DG以便將所有角色切換到最開始的狀態(150主庫,200備庫)

3.1 引數檔案不需要改變
3.2 在200(此時主庫)建立備庫控制檔案並scp到150
[oracle@stream dbs]$ sqlplus / as sysdba
SQL> create spfile from pfile;
SQL> startup mount
SQL> alter database create standby controlfile as '/u01/control01.dbf';
SQL> exit
[oracle@stream dbs]$ cd /u01
[oracle@stream u01]$ scp control01.dbf 192.168.249.150:/u01/app/oracle/oradata/ora10g/ 
3.3 將200(此時主庫)的資料檔案和日誌檔案傳到150上
[oracle@stream u01]$ cd app/oracle/oradata/ora10g/
[oracle@stream ora10g]$ scp *.dbf *.log 192.168.249.150:/u01/app/oracle/oradata/ora10g/
3.4 在200上將主庫啟動到open狀態
[oracle@stream ora10g]$ sqlplus / as sysdba
SQL> alter database open;
SQL>  select name,database_role,open_mode,protection_mode from v$database;

NAME      DATABASE_ROLE    OPEN_MODE  PROTECTION_MODE
--------- ---------------- ---------- --------------------
ORA10G    PRIMARY          READ WRITE MAXIMUM PERFORMANCE
SQL> select switchover_status from v$database;

SWITCHOVER_STATUS---狀態不正常應該是因為150(備庫)還沒有mount,也沒應用redo
--------------------
NOT ALLOWED
3.5 啟動此時的備庫150到mount
SQL> startup mount
ORACLE instance started.

Total System Global Area  373293056 bytes
Fixed Size                  1273780 bytes
Variable Size             113246284 bytes
Database Buffers          255852544 bytes
Redo Buffers                2920448 bytes
Database mounted.
SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
TO PRIMARY

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /arch/log
Oldest online log sequence     1
Next log sequence to archive   2
Current log sequence           2
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /arch/log
Oldest online log sequence     1
Next log sequence to archive   2
Current log sequence           2
3.6 備庫應用redo

SQL> alter database recover managed standby database disconnect from session;

Database altered.

3.7 在200上切換日誌
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /arch/log
Oldest online log sequence     3
Next log sequence to archive   5
Current log sequence           5
SQL> alter system switch logfile;

System altered.

SQL> /

System altered.

SQL> /

System altered.

SQL> select switchover_status from v$database;

SWITCHOVER_STATUS---
--------------------
TO STANDBY

SQL> !date
Fri May 11 00:41:35 CST 2012

3.8 備庫檢視歸檔是否已經傳遞過來

SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /arch/log
Oldest online log sequence     1
Next log sequence to archive   2
Current log sequence           2
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /arch/log
Oldest online log sequence     1
Next log sequence to archive   2
Current log sequence           2
SQL> archive log list
Database log mode              Archive Mode
Automatic archival             Enabled
Archive destination            /arch/log
Oldest online log sequence     1
Next log sequence to archive   0
Current log sequence           8
SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
SESSIONS ACTIVE

待DG重新搭建好以後(200為主庫,150為備庫),現在再將150變為主庫,200變為備庫
4、 切換
4.1 200上
SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
TO STANDBY

SQL> !date
Fri May 11 00:41:35 CST 2012

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  373293056 bytes
Fixed Size                  1273780 bytes
Variable Size             113246284 bytes
Database Buffers          255852544 bytes
Redo Buffers                2920448 bytes
Database mounted.
SQL> alter database recover managed standby database disconnect from session;

Database altered.

SQL>  select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
SESSIONS ACTIVE

SQL>  select name,database_role,open_mode,protection_mode from v$database;

NAME      DATABASE_ROLE    OPEN_MODE  PROTECTION_MODE
--------- ---------------- ---------- --------------------
ORA10G    PHYSICAL STANDBY MOUNTED    MAXIMUM PERFORMANCE

4.2 150上:
SQL> select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
SESSIONS ACTIVE

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,database_role,open_mode,protection_mode from v$database;

NAME      DATABASE_ROLE    OPEN_MODE  PROTECTION_MODE
--------- ---------------- ---------- --------------------
ORA10G    PRIMARY          READ WRITE MAXIMUM PERFORMANCE

SQL>  select switchover_status from v$database;

SWITCHOVER_STATUS
--------------------
TO STANDBY

5、此時已經完全恢復到我們所做測試前的狀態

測試完畢!!

 


 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24500180/viewspace-723325/,如需轉載,請註明出處,否則將追究法律責任。