Oracle 12c R2中的ADG會(huì)話保留特性
Oracle 12c R2中有一個(gè)不錯(cuò)的特性,那就是Active Data Guard會(huì)話保留,原本的叫法是Preserving Active Data Guard Application Connections
怎么理解呢,比如在Active Data Guard上的連接會(huì)話,在switchover的過(guò)程中會(huì)話連接會(huì)始終保持不會(huì)中斷。這一點(diǎn)聽起來(lái)就很有特點(diǎn),能夠提高用戶體驗(yàn)度,而且是一種相對(duì)透明的方式。
到底怎么樣呢,我們來(lái)簡(jiǎn)單測(cè)試一下,先看看默認(rèn)情況下的ADG會(huì)話情況,切換的過(guò)程就直接使用DG Broker來(lái)做了,快。
這是一個(gè)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)我們連接到備庫(kù),備庫(kù)現(xiàn)在是ADG模式。
- SQL> select open_mode from v$database;
- OPEN_MODE
- ----------------------------------------
READ ONLY WITH APPLY如果這個(gè)時(shí)候我們就使用一條語(yǔ)句在備庫(kù)端查詢,使用TNS連接,然后DG Broker來(lái)切換,切換的情況如下,也是一氣呵成。
- 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ù)測(cè)試連接的情況如下:
- 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
可以看到在切換的過(guò)程中,連接被中斷了,而接下來(lái)就會(huì)徹底斷開連接。
- SQL> /
- ERROR:
- ORA-03114: not connected to ORACLE
這里就需要說(shuō)一下這個(gè)特性的情況,其實(shí)還涉及到一個(gè)參數(shù)standby_db_preserve_states,默認(rèn)是NONE
- SQL> show parameter standby_db_preserve_states
- NAME TYPE VALUE
- ------------------------------------ ---------------------- ------
- standby_db_preserve_states string NONE
我們?cè)O(shè)置為ALL,這個(gè)修改需要重啟備庫(kù),我們?cè)O(shè)置好之后,再來(lái)做switchover
步驟和上面的類似,我們直接來(lái)看看效果,始終在這一個(gè)會(huì)話內(nèi)查看數(shù)據(jù)查詢的情況,整個(gè)過(guò)程相對(duì)平滑,在切換過(guò)程中會(huì)有一個(gè)大約兩秒的停頓,但是連接始終是保持的。
- COUNT(*)
- ----------
- 153
- SQL> /
- COUNT(*)
- ----------
- 153
- SQL> /
- COUNT(*)
- ----------
- 153
- SQL> /
- COUNT(*)
- ----------
- 153
- SQL> /
- COUNT(*)
- ----------
- 153
整體來(lái)看這個(gè)特性確實(shí)達(dá)到了預(yù)期的效果,還是蠻不錯(cuò)的。