Oracle Dataguard一共支持三種模式:最大可用模式(Maximum Availability),最大性能模式(Maximum Performance),最大保護模式(Maximum Protection)。默認創建的是最大性能模式(Maximum Performance)。關於三者的區別,我們來看官方的定義。
Maximum Availability
Transactions do not commit until all redo data needed to recover those transactions has been written to the online redo log and to the standby redo log on at least one synchronized standby database.If the primary database cannot write its redo stream to at least one synchronized standby database,it operates as if it were in maximum performance mode to preserve primary database availability until it is again able to write its redo stream to a synchronized standby database.
Maximum Performance
This is accomplished by allowing transactions to commit as soon as all redo data generated by those transactions has been written to the online log. Redo data is also written to one of more standby databases,but this is done asynchronously with respect to transaction commitment,so primary database performance is unaffected by delays in writing redo data to the standby databases.
Maximum Protection
This protection mode ensures that no data loss will occur if the primary database fails.To provide this level of protection,the redo data needed to recover a transaction must be written to both the online redo log and to the standby redo on at least one synchronized standby database before the transaction commits.To ensure that data loss cannot occur,the primary database will shut down,rather than continue processing transactions,if it cannot write its redo stream to at least one synchronized standby database.
三種模式對於日志傳輸的要求如下:
在前篇文章中-《Oracle Dataguard之物理standby的基本配置》,我們最后配置出來的是Physical Standby Database 最大性能模式下的異步傳輸,現在我們配置該模式下的Real-Time Apply。啟用Real-Time Apply需要配置standby redo log,而這也是其它兩種模式的基礎。
一、 創建standby redo log
1> 查詢主庫上online redo log的組數和大小 -->> node1 上操作
SQL> select group#,bytes/1024/1024 "size" from v$log;
GROUP# size
------ ----------
1 50
2 50
3 50
2> 在備庫上添加standby redo log -->> group比主庫多一組,大小和主庫一樣,node2上操作
[oracle@node2 ~]$ mkdir /u01/standby
SQL> alter database add standby logfile '/u01/standby/standby01.log' size 50M;
SQL> alter database add standby logfile '/u01/standby/standby02.log' size 50M;
SQL> alter database add standby logfile '/u01/standby/standby03.log' size 50M;
SQL> alter database add standby logfile '/u01/standby/standby04.log' size 50M;
注意:請確保已關閉Redo Apply,不然會報以下錯誤
SQL> alter database add standby logfile '/u01/standby/standby01.log' size 50M;
alter database add standby logfile '/u01/standby/standby01.log' size 50M
*
ERROR at line 1:
ORA-01156: recovery or flashback in progress may need access to files
關閉Redo Apply,
SQL> alter database recover managed standby database cancel;
二、 修改主庫的配置參數 -->> node1 上操作
SQL> alter system set log_archive_dest_2='service=to_victor lgwr affirm sync valid_for=(online_logfiles,primary_role) db_unique_name=victor';
SQL> alter system switch logfile;
三、 在備庫上啟用Real-Time Apply -->> node2 上操作
SQL> alter database recover managed standby database using current logfile disconnect from session;
四、 測試
除了用前篇文章中,查看歸檔日志的應用情況來驗證dataguard的配置以外,本文將采用實際案例進行測試。
1> 在主庫上新建一個測試表
SQL> create table test(id number);
SQL> insert into test values(1);
2> 在備庫中檢測
SQL> select * from test;
no rows selected
3> 在主庫中提交事務
SQL> commit;
4> 在備庫中檢測
SQL> select * from test;
ID
----------
1
總結:
這個總結包括物理standby的基本配置和本文中的Real-Time Apply
1> 如果只設置主/次兩個本地歸檔目的地,可以使用初始化參數log_archive_dest指定主歸檔目的地,使用初始化參數log_archive_duplex_dest指定次歸檔目的地。
在數據庫中,初始換參數log_archive_dest和log_archive_duplex_dest與log_archive_dest_n只能使用一組來設置歸檔目的地,不能同時使用
2> 備庫log_archive_dest_1如果沒有顯性指定,默認的歸檔目錄將是$ORACLE_HOME/dbs.倘若顯性指定,但valid_for不是
(standby_logfiles,standby_role)或者(all_logfiles,all_roles),則該設置無效,報警日志中將報以下錯誤:
ORA-16032: parameter STANDBY_ARCHIVE_DEST destination string cannot be translated
歸檔目錄將繼續為$ORACLE_HOME/dbs
3> 在本文中,log_archive_dest_1='location=/u01/archivelog valid_for=(standby_logfiles,standby_role) db_unique_name=victor',如果再顯性指定
log_archive_dest_3='location=/u01/standbyarchive valid_for=(standby_logfiles,standby_role) db_unique_name=victor',將會有兩份standby的
歸檔日志產生,沒有必要,只需要一個log_archive_dest_1即可
4> 最大性能模式下,如果是async,即異步,則需要主庫切一次日志,備庫采用應用。而如果啟用Real-Time Apply,則只需要主庫事務commit, 備庫就能應用
5> 刪除日志
SQL> alter database drop logfile group 7;
6> 如果發出了alter database recover managed standby database cancel;這個命令,MRP(Media Recovery process)將停止工作,但
RFS(Remote file server)仍繼續工作
7> 如果沒有standby redo logs,是不能啟動real time apply的
SQL> alter database recover managed standby database using current logfile disconnect from session;
alter database recover managed standby database using current logfile disconnect from session
*
ERROR at line 1:
ORA-38500: USING CURRENT LOGFILE option not available without standby redo logs
8> standby數據庫startup后,沒有發出alter database recover managed standby database disconnect from session這個命令,RFS仍然工作,只要監聽
都ok
9> disconnect from session代表這個命令后台運行。
10> Real-Time Apply的原理圖