Oracle 12c R2中的ADG會話保留特性
Oracle 12c R2中有一個不錯的特性,那就是Active Data Guard會話保留,原本的叫法是Preserving Active Data Guard Application Connections
怎么理解呢,比如在Active Data Guard上的連接會話,在switchover的過程中會話連接會始終保持不會中斷。這一點聽起來就很有特點,能夠提高用戶體驗度,而且是一種相對透明的方式。
到底怎么樣呢,我們來簡單測試一下,先看看默認情況下的ADG會話情況,切換的過程就直接使用DG Broker來做了,快。
這是一個12cR2的環(huán)境,也使用了Far Sync。
- DGMGRL>show configuration
- Configuration - dg_test12cs
- Protection Mode: MaxPerformance
- Members:
- test12cs - Primary database
- test_sync - Far sync instance
- test12css - Physical standby database
- Fast-Start Failover: DISABLED
- Configuration Status:
SUCCESS (status updated 10 seconds ago)我們連接到備庫,備庫現(xiàn)在是ADG模式。
- SQL> select open_mode from v$database;
- OPEN_MODE
- ----------------------------------------
READ ONLY WITH APPLY如果這個時候我們就使用一條語句在備庫端查詢,使用TNS連接,然后DG Broker來切換,切換的情況如下,也是一氣呵成。
- DGMGRL> switchover to test12css
- Performing switchover NOW, please wait...
- Operation requires a connection to database "test12css"
- Connecting ...
- Connected to "test12css"
- Connected as SYSDBA.
- New primary database "test12css" is opening...
- Operation requires start up of instance "test12cs" on database "test12cs"
- Starting instance "test12cs"...
- for RDBMS instance
- ORACLE instance started.
- Database mounted.
- Database opened.
- Connected to "test12cs"
- Switchover succeeded, new primary is "test12css"
- DGMGRL>
在客戶端反復(fù)測試連接的情況如下:
- SQL> select count(*) from cat;
- COUNT(*)
- ----------
- 153
- SQL> /
- COUNT(*)
- ----------
- 153
- SQL> /
- select count(*) from cat
- *
- ERROR at line 1:
- ORA-03113: end-of-file on communication channel
- Process ID: 94489
- Session ID: 419 Serial number: 62932
可以看到在切換的過程中,連接被中斷了,而接下來就會徹底斷開連接。
- SQL> /
- ERROR:
- ORA-03114: not connected to ORACLE
這里就需要說一下這個特性的情況,其實還涉及到一個參數(shù)standby_db_preserve_states,默認是NONE
- SQL> show parameter standby_db_preserve_states
- NAME TYPE VALUE
- ------------------------------------ ---------------------- ------
- standby_db_preserve_states string NONE
我們設(shè)置為ALL,這個修改需要重啟備庫,我們設(shè)置好之后,再來做switchover
步驟和上面的類似,我們直接來看看效果,始終在這一個會話內(nèi)查看數(shù)據(jù)查詢的情況,整個過程相對平滑,在切換過程中會有一個大約兩秒的停頓,但是連接始終是保持的。
- COUNT(*)
- ----------
- 153
- SQL> /
- COUNT(*)
- ----------
- 153
- SQL> /
- COUNT(*)
- ----------
- 153
- SQL> /
- COUNT(*)
- ----------
- 153
- SQL> /
- COUNT(*)
- ----------
- 153
整體來看這個特性確實達到了預(yù)期的效果,還是蠻不錯的。