【DataGuard】Oracle 11g DataGuard 新特性之 Active Standby:Real-Time Apply+Query

kunlunzhiying發表於2016-12-01
Oracle 11g DataGuard 新特性之 Active Standby:Real-Time Apply+Query


oracle 11g之前的版本。 物理備庫處於日誌應用狀態時,是無法從備庫讀取資料的。如果想開庫,需停止日誌應用,備庫可以開到read only狀態。
如果物理備庫從read only狀態回到日誌應用狀態,要先關掉物理備庫,再將庫啟到mount狀態,最後重新應用日誌。

這樣要從備庫讀資料,日誌應用就必須停掉。無法實現邊應用日誌、邊讀取資料。

11g 可以使用active standby,實現日誌應用和查詢同時進行。即Real-Time Apply + Real-Time Query.




【實驗環境】
Red Hat Enterprise Linux Server release 5.4
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0

【DG主庫、物理備庫結構資訊】


【實驗過程】
主庫 Primary database綠色
物理備庫 Physical standby database:黃色

一、物理備庫應用日誌

檢視角色、狀態和保護模式

select database_role,open_mode from v$database;
主庫處於read write狀態,備庫處於mounted狀態





物理備庫 應用日誌

alter database recover managed standby database disconnect;




二、物理備庫開庫
物理備庫在處於日誌應用狀態時,是無法開庫進行資料查詢的。直接嘗試開庫會報錯。

直接嘗試open備庫報錯
select instance_name,status from v$instance;
alter database open;


模擬生產環境中需要做報表,要查詢物理備庫資料。

物理備庫取消日誌應用:

alter database recover managed standby database cancel;

物理備庫開庫(read only

alter database open;

select database_role,open_mode from v$database;



此時備庫處於Read Only狀態,可以進行資料查詢,但無法應用日誌。

如果物理備庫從read only狀態回到日誌應用工狀態,要先關掉物理備庫,再將庫啟到mount狀態,最後重新應用日誌。

shutdown immediate;

mount startup mount;

alter database recover managed standby database disconnect from session; 

這種日誌應用方式無法實現備庫上日誌應用和資料查詢同時進行。
如果想實現Active Standby,即日誌實時應用 同時備庫可以進行資料查詢,備庫上需使用Real-Time Apply來應用日誌。

【Oracle官方文件中對Real-Time Apply介紹】

If the real-time apply feature is enabled, apply services can apply redo data as it is received, without waiting for the current standby redo log file to be archived. This results in faster switchover and failover times because the standby redo log files have been applied already to the standby database by the time the failover or switchover begins.

Use the ALTER DATABASE statement to enable the real-time apply feature, as follows:

  • For physical standby databases, issue the ALTER DATABASE RECOVER MANAGED STANDBY DATABASE USING CURRENT LOGFILE statement.

  • For logical standby databases, issue the ALTER DATABASE START LOGICAL STANDBY APPLY IMMEDIATE statement.

Real-time apply requires a standby database that is configured with a standby redo log and that is in ARCHIVELOG mode.

Figure 7-1 shows a Data Guard configuration with a local destination and a standby destination. As the remote file server (RFS) process writes the redo data to standby redo log files on the standby database, apply services can recover redo from standby redo log files as they are being filled.





三、物理備庫Real-Time Apply 應用日誌
1、主庫日誌傳輸方式
如果要實現真正的日誌實時應用、資料實時查詢,日誌的遠端傳輸方式必須是LGWR、SYNC、AFFIRM


2、備庫新增standby日誌組
先檢視當前日誌組數量和位置


select sequence#,group#,bytes/1024/1024 MB from v$log;

select member from v$logfile;



要新增4個 standby 日誌組 ,比普通日誌組多一個

alter database add standby logfile group 4 '/u02/oradata/sh/redo04.std' size 50m;

alter database add standby logfile group 5 '/u02/oradata/sh/redo05.std' size 50m;

alter database add standby logfile group 6 '/u02/oradata/sh/redo06.std' size 50m;

alter database add standby logfile group 7 '/u02/oradata/sh/redo07.std' size 50m;





3、備庫Real-Time Apply應用日誌

alter database recover managed standby database using current logfile disconnect;

select database_role,open_mode from v$database;





【實驗結論】
通過在物理備庫新增standby日誌組,設定主庫遠端歸檔傳輸方式為LGWR、SYNC、AFFIRM並在備庫上使用Real-Time Apply 應用日誌,實現備庫Read Only With Apply狀態開庫。即在日誌應用過程中,同時只讀方式開庫來讀取資料。

實現了DataGuard物理備庫的日誌應用和資料讀取的同時進行。


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

相關文章