靜態FAILOVER

yangtingkun發表於2010-11-07

以前寫過關於RACFAILOVER文章,不過當時關注的是動態的FAILOVER特性,而OracleTNSNAMES.ORA中可以同時配置動態FAILOVER和靜態FAILOVER

 

 

靜態FAILOVER就是連線時FAILOVER,也就是說當使用者配置了多個IP地址後,當一個地址無法訪問時,會自動透過其他的地址進行訪問,而不會返回錯誤給使用者。

測試環境為10.2.0.4 Rac for Solaris for sparc 64

SQL> SELECT * FROM V$VERSION;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production
CORE    10.2.0.4.0      Production
TNS for Solaris: Version 10.2.0.4.0 - Production
NLSRTL Version 10.2.0.4.0 - Production

SQL> SELECT NAME FROM V$DATABASE;

NAME
---------
TESTRAC

SQL> SELECT INSTANCE_NUMBER, INSTANCE_NAME FROM GV$INSTANCE;

INSTANCE_NUMBER INSTANCE_NAME
--------------- ----------------
              1 testrac1
              2 testrac2

為了避免REMOTE_LISTENER的影響,先將引數置為空:

SQL> ALTER SYSTEM SET REMOTE_LISTENER = '' SCOPE = BOTH;

系統已更改。

檢查節點1上配置:

SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac1

SQL> SHOW PARAMETER LISTENER

NAME             TYPE        VALUE
---------------- ----------- ------------------------------
local_listener   string      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.224)(PORT = 1521))
remote_listener  string

節點2上的引數配置:

SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac2

SQL> SHOW PARAMETER LISTENER

NAME             TYPE        VALUE
---------------- ----------- ------------------------------
local_listener   string      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.225)(PORT = 1521))
remote_listener  string

將資料庫的TESTRAC1服務名配置為:

TESTRAC1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.224)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.225)(PORT = 1521))
      (FAILOVER = ON )
    )
    (CONNECT_DATA =
      (SERVICE_NAME = TESTRAC)
    )
  )

關閉例項1

bash-2.03$ srvctl stop inst -d testrac -i testrac1

檢查連線會話:

SQL> CONN YANGTK/YANGTK@TESTRAC1
已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac2

SQL> SELECT FAILOVER_TYPE, FAILOVER_METHOD, FAILED_OVER
  2  FROM V$SESSION
  3  WHERE SID IN (
  4  SELECT SID
  5  FROM V$MYSTAT
  6  WHERE ROWNUM = 1);

FAILOVER_TYPE FAILOVER_M FAI
------------- ---------- ---
NONE          NONE       NO

由於配置了靜態FAILOVER,當連線例項1失敗時,自動可以連線到例項2上,而且從V$SESSION的查詢中可以看到,這裡動態FAILOVER並沒有生效,起作用的是靜態FAILOVER特性。

如果將FAILOVER設定為OFF

TESTRAC1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.224)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.225)(PORT = 1521))
      (FAILOVER = OFF )
    )
    (CONNECT_DATA =
      (SERVICE_NAME = TESTRAC)
    )
  )

測試TESTRAC1服務名:

SQL> CONN YANGTK/YANGTK@TESTRAC1
ERROR:
ORA-12514: TNS:
監聽程式當前無法識別連線描述符中請求的服務


警告: 您不再連線到 ORACLE

連線報錯,說明再FAILOVER設定為OFF的情況下,連線不會嘗試其他的地址。

如果將地址中IP的次序調換:

TESTRAC1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.225)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.224)(PORT = 1521))
      (FAILOVER = OFF )
    )
    (CONNECT_DATA =
      (SERVICE_NAME = TESTRAC)
    )
  )

再次測試連線:

SQL> CONN YANGTK/YANGTK@TESTRAC1
已連線。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;

INSTANCE_NAME
----------------
testrac2

可以看到,如果不指定FAILOVERON,則Oracle只會嘗試地址列表中的第一個地址,而選擇忽略其他的配置,如果設定FAILOVERON,則Oracle會嘗試所有的地址。

需要注意一點,一旦新增了INSTANCE_NAME的設定,則FAILOVER的設定不再有效

而如果配置服務名如下:

TESTRAC1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.224)(PORT = 1521))
      (ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.225)(PORT = 1521))
      (FAILOVER = ON )
    )
    (CONNECT_DATA =
      (SERVICE_NAME = TESTRAC)
      (INSTANCE_NAME = TESTRAC1)
    )
  )

測試連線:

SQL> CONN YANGTK/YANGTK@TESTRAC1
ERROR:
ORA-12521: TNS:
監聽程式當前無法識別連線描述符中請求的例項


警告: 您不再連線到 ORACLE

 

 

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

相關文章