天天看點

Data Guard Broker系列之五:資料庫角色轉換

switchoverswitchover是primary資料庫和它的一個standby資料庫之間角色的切換,通常是有計劃的資料庫轉換,保證不會有資料丢失。failoverfailover發生在primary資料庫失敗之後,它的一個standby接替它成為primary資料庫。failover通常發生primary資料庫不可恢複的情況下,根據資料庫保護模式的不一樣failover可能會有資料丢失。

對于switchover操作來說,遵循以下的步驟

首先選擇未應用的redo的standby,這個可以通過show database db_unique_name recvqentries看到。

對于實體和邏輯standby同時存在時,優先選擇redo apply queue最小的實體standby,因為實體standby在轉換之後所有的standby都能正常工作,而轉換到邏輯standby之後同一組裡面的實體standby将要重建。

對failover操作來說,遵循以下的步驟

為降低資料丢失的數量,首先要選擇應用日志最多的standby。

對于實體和邏輯standby同時存在時,優先選擇實體standby,因為實體standby在轉換之後所有的standby都能正常工作,而轉換到邏輯standby之後同一組裡面的standby将要重建。另外一個如果邏輯standby使用dbms_logstdby.skip忽略了一部 分資料庫話也會造成資料丢失。

第一個層次是在沒有配置broker的環境中,在這種環境下,如果要進行資料庫的角色卻換的話通常需要3個步驟:

首先是檢查data guard環境中的資料庫是否滿足轉換的條件。

然後登陸到primary資料庫運作sql轉換角色,再重新開機primary資料庫使其變成standby。

再登入到要轉換的standby資料庫上,運作sql轉換角色,再重新啟動standby以變成新的primary。

第二個層次是配置了broker但是沒有配置fsf(fast-start failover)的環境中,在這裡做switchover和failover都隻需要一個簡單的指令,剩下的重新開機primary和standby的操作就交給broker去做了。

第三個層次是配置了fsf的機器,這時候資料庫的狀态由fsf observer監控着,一旦primary資料庫出現了問題需要failover操作,fsf會自動進行資料庫的轉換,根本就不需要人來參與了。

broker管理下的switchover的過程

檢查primary和standby是否online,是否有錯誤,如果有錯誤則switchover失敗。

如果primary是rac,則關掉rac中所有不參與switchover的instance。

将primary資料庫轉換成standby資料庫,然後将目标standby資料庫轉換成新的primary資料庫。

更新broker控制檔案記錄轉換之後的資料庫角色資訊。

如果新的standby是實體standby的話将會重新開機之,然後開始redo log應用。rac環境中将會重新開機那些被關閉的instance。

如果是實體standby環境的話重新開機新的primary資料庫然後開始rodo log的傳送到其他的standby中。

最後broker會确認轉換之後的新primary和standby都工作正常,redo log傳送和應用都正常。對于那些沒有參與switchover的standby将會保持不變。

下面是一個switchover的詳細過程

dgmgrl> show configuration

configuration

  name:                fsf

  enabled:             yes

  protection mode:     maxavailability

  fast-start failover: disabled

  databases:

    torcla - physical standby database

    torclb - primary database

current status for "fsf":

success

dgmgrl> switchover to torcla

performing switchover now, please wait...

operation requires shutdown of instance "torclb" on database "torclb"

shutting down instance "torclb"...

ora-01109: database not open

database dismounted.

oracle instance shutdown.

operation requires shutdown of instance "torcla" on database "torcla"

shutting down instance "torcla"...

operation requires startup of instance "torclb" on database "torclb"

starting instance "torclb"...

oracle instance started.

database mounted.

operation requires startup of instance "torcla" on database "torcla"

starting instance "torcla"...

switchover succeeded, new primary is "torcla"

    torcla - primary database

    torclb - physical standby database

failover有兩種類型:完全failover和立即failover。

完全failover進行完全failover操作的是很broker會竟可能的恢複資料,同時在failover完成之後會根據情況盡可能的将沒有參與failover的standby變成新的primary的可用的standby。立即failover立即failover的操作開始之後broker不再去試圖恢複更多的資料,另一個就是failover完成之後所有沒有參與failover的standby都要重新啟用。

調用這兩種failover的指令如下

-- 完全failover

failover to standby_database_name;

-- 立即failover

failover to standby_database_name immediate;

檢查primary是否可用,可用的話給出一條警告資訊。

确認目标standby可用,不可用的話failover失敗。rac環境中将關閉standby的其他不參與的instance。

等待目标standby完成還在隊列中的redo資訊之後關閉redo log apply或是sql apply。

将目标standby轉換成新的primary。

将新的primary資料庫打開為讀寫模式。

檢查其他的standby是否能成為新primary的standby,如果可以的話則該standby的狀态保證不變,否則則需要re-enable。

啟動redo傳送服務将redo傳送給那些不需要re-enable的standby資料庫。

如果是rac環境則重新開機那些之前關閉的instance。

立即停止redo log apply或是sql apply,不管是否還有可恢複的資料,這樣可能會造成資料丢失。

将目标standby轉換成新的primary并打開到讀寫模式,并啟動redo傳送服務。

一個完全failover的例子

dgmgrl> failover to torclb

performing failover now, please wait…

failover succeeded, new primary is “torclb”

dgmgrl> show configuration

name: fsf enabled: yes protection mode: maxperformance fast-start failover: disabled databases: torcla – physical standby database (disabled) torclb – primary database

current status for “fsf”:

從上面的狀态我們可以看到此時的新standby是不可用的,處于disabled狀态。

在角色轉換之後我們可能還需要進行額外的操作來啟用被禁用的資料庫,操作已經data guard的類型不同需要啟用資料庫情況也不同。

轉換操作 reinstate或recreate 有問題的primary資料庫 重新啟用沒有參與failover的standby

switchover到實體standby

不需要其他操作

switchover到邏輯standby

所有實體standby需要recreate

完全failover到實體standby

如果啟用了flashback而且retention足夠的話可以reinstate,否則隻能recreate

對于實體standby如果啟用了flashback而且retention足夠的話可以reinstate,否則隻能recreate

對于邏輯standby必須recreate

完全failover邏輯standby

所有standby都會被disabled,都需要recreate

立即failover到實體standby或邏輯standby

必須要recreate

在broker中進行reinstate資料庫操作隻需要運作一個指令就行了,不過前提是配置了flashback以及足夠的retention。

reinstate database db_unique_name;

基本步驟是:

重新開機資料庫到mount狀态

使用dgmgrl連接配接到primary資料庫

運作reinstate database指令

下面對上一步failover之後的新standby做一次reinstate操作

dgmgrl> reinstate database torcla

reinstating database "torcla", please wait...

continuing to reinstate database "torcla" ...

reinstatemen to fdatabase "torcla" succeeded

  protectionmode:     maxperformance

可以看到reinstate之後資料庫torcla已經可以正常使用了。

參考至:http://www.dbabeta.com/2009/learn-data-guard-broker_role-transition.html

如有錯誤,歡迎指正

郵箱:[email protected]

作者:czmmiao  文章出處:http://czmmiao.iteye.com/blog/2124881