Oracle 11g Active Dataguard Failover實驗

來源:互聯網
上載者:User

Dataguard是Oracle官方推薦MAA架構的重要解決方案。目前RAC+Local Dataguard + Remote Dataguard已經成為行業界普遍使用的HA架構方式。無論對於RAC還是Dataguard,實現switchover和failover都是最常用的操作環境。
 
Failover是一種“unplanned”切換動作。通常是主庫Primary出現軟硬體故障問題,不能夠繼續對外提供資料訪問服務,就需要強制性的斷開Primary,使用Standby來充當資料訪問點。11g的Active Data Guard中,Standby通常是作為Read Only With Apply狀態進行工作,提供出一個唯讀資料訪問來源,類比讀寫分離的架構方式。在進行Failover之後,Primary庫實際上是退出了Oracle HA架構體系,成為游離對象。Standby在切換之後就成為新的Primary。這個過程就是角色切換。
 
Switchover動作是不會引起資料丟失的,Standby可以保證接受並且應用所有的Redo Log資料。而Failover則不好說,根據不同的保護模式(Protection Mode),一個事務在主庫上面是否被commit,是取決於standby上是否接受和應用上日誌資料。所以,在進行Failover的時候,是可能會丟資料的。我們作為DBA,需要考慮的是在Primary網站site允許的情況下(因為Primary故障情況不明),儘可能的保護資料,減少資料丟失(Gap)。
 
本篇主要進行Failover過程的實驗示範。

相關參考:

Oracle Data Guard 重要配置參數

基於同一主機配置 Oracle 11g Data Guard

探索Oracle之11g DataGuard

Oracle Data Guard (RAC+DG) 歸檔刪除策略及指令碼

Oracle Data Guard 的角色轉換

Oracle Data Guard的日誌FAL gap問題

Oracle 11g Data Guard Error 16143 Heartbeat failed to connect to standby 處理方法

 

1、實驗環境說明

 

我們依然使用ora11g和ora11gsy配對節點。Primary為ora11g,Standby為ora11gsy,兩邊版本均為11.2.0.4。

先啟動ora11gsy,啟動standby端。

 

[oracle@SimpleLinux ~]$ export ORACLE_SID=ora11gsy

[oracle@SimpleLinux ~]$ sqlplus /nolog

 

SQL*Plus: Release 11.2.0.4.0 Production on Mon Apr 21 21:27:28 2014

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

 

SQL> conn / as sysdba

Connected to an idle instance.

SQL> startup

ORACLE instance started.

 

Total System Global Area  372449280 bytes

Fixed Size                  1364732 bytes

Variable Size            331353348 bytes

Database Buffers          33554432 bytes

Redo Buffers                6176768 bytes

Database mounted.

Database opened.

 

啟動apply過程。

 

--Standby端啟動後預設為Read Only。

SQL> select open_mode from v$database;

 

OPEN_MODE

--------------------

READ ONLY

 

SQL> alter database recover managed standby database using current logfile disconnect from session;
 
 

Database altered.

 

SQL> select open_mode from v$database;

 

OPEN_MODE

--------------------

READ ONLY WITH APPLY

 

之後啟動Primary端。

 

 

[oracle@SimpleLinux ~]$ env | grep ORACLE_SID

ORACLE_SID=ora11g

[oracle@SimpleLinux ~]$ sqlplus /nolog

 

SQL*Plus: Release 11.2.0.4.0 Production on Tue Apr 22 15:26:29 2014

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

 

SQL> conn / as sysdba

Connected to an idle instance.

SQL> startup

ORACLE instance started.

 

Total System Global Area  313860096 bytes

Fixed Size                  1364340 bytes

Variable Size            272633484 bytes

Database Buffers          33554432 bytes

Redo Buffers                6307840 bytes

Database mounted.

Database opened.

 

2、Failover實驗

 

我們人工類比Primary崩潰,直接關閉。

 

SQL> shutdown abort

ORACLE instance shut down.

 

真實環境下,Primary的故障是多樣的,現象也是多樣的。最徹底的就是Primary網站直接失去聯絡,不能訪問。這種情況出現並不多,但是也能出現。比如磁碟(非冗餘)損壞、斷電、地震天災。最簡單的情況也許是監聽器停止工作需要重啟、執行個體停止等等。
 
故障的多樣,也就意味著恢複的機會是多樣的。在11g裡面,Oracle認為最理想的情況是,雖然Oracle資料庫不能開啟,但是可以啟動到mount狀態。

Mount狀態之所以重要,就在於如果可以到這個階段,控制檔案control_file就可以讀取到,歸檔日誌和線上日誌的位置、資訊都可以讀取到。這也就意味著最大可能性的進行資料恢複,避免資料損失。
 
在11g中,推出了日誌手工flush的功能,來彌補日誌資料沒有傳遞的問題。

 

SQL> startup mount

ORACLE instance started.

 

Total System Global Area  313860096 bytes

Fixed Size                  1364340 bytes

Variable Size            272633484 bytes

Database Buffers          33554432 bytes

Redo Buffers                6307840 bytes

Database mounted.

 

進行日誌重新整理:

 

SQL> alter system flush redo to 'ora11gsy';

System altered.

 

此時,alert log中顯示資訊,將日誌傳遞。

 

Tue Apr 22 15:31:00 2014

Resetting standby activation ID 4239920854 (0xfcb80ed6)

Tue Apr 22 15:31:00 2014

Archived Log entry 14 added for thread 1 sequence 27 ID 0xfcb80ed6 dest 1:

Media Recovery Waiting for thread 1 sequence 28

Tue Apr 22 15:31:00 2014

Standby switchover readiness check: Checking whether recoveryapplied all redo..

Physical Standby applied all the redo from the primary.

 

檢查日誌gap的問題,可以查看視圖v$archive_gap。

 

SQL> select thread#, low_sequence#, high_sequence# from v$archive_gap;

no rows selected

 

如果沒有發現明顯的gap現象,說明此次的failover不會有資料損失情況。在standby端,要進行關閉apply和結束應用動作。

 

 

SQL> alter database recover managed standby database cancel;

Database altered.

 

 

SQL> alter database recover managed standby database finish;

Database altered

 

 

SQL> select open_mode, switchover_status from v$database;

OPEN_MODE            SWITCHOVER_STATUS

-------------------- --------------------

READ ONLY            TO PRIMARY

 

注意:這個過程並不會經常成功執行,而且在10g這樣的版本下也沒有辦法自動flush redo。解決的方法也是有的,就是從Primary目錄中,將日誌拷貝到Standby端,手工去載入。
 
 

更多詳情見請繼續閱讀下一頁的精彩內容:

  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.