Oracle Failover - TAF 透明應用切換

tolywang發表於2010-04-01

failover = 

(DESCRIPTION =

(enable=broken)

(LOAD_BALANCE = yes)

(ADDRESS = (PROTOCOL = TCP)(HOST = hprac-22)(PORT = 1521))

(ADDRESS = (PROTOCOL = TCP)(HOST = hprac-23)(PORT = 1521))

(ADDRESS = (PROTOCOL = TCP)(HOST = hprac-24)(PORT = 1521))

(ADDRESS = (PROTOCOL = TCP)(HOST = hprac-25)(PORT = 1521))

(CONNECT_DATA =

(SERVICE_NAME = rac)

(failover_mode=(type=select)(method=basic))

)

)


對於已有連線的失敗切換,首先要求FAILOVER = ON,並且設定了FAILOVER_MODE

FAILOVER_MODE的子引數含義:

TYPE:1)session---如果使用者連線丟失,將建立一個新的會話連線到備用節點,使用者的所有未提交的操作必須回滾,然後再次執行,SELECT操作也被中止.

2)select---如果使用者連線丟失,將使用遊標和之前的快照繼續執行SELECT操作,叫做SQL接管,SQL接管能夠無縫接管理的事務型別只有SELECT語句.其它的操作也必須要回滾然後再次執行.

3)none---客戶端預設值,禁止SQL接管功能,主要用於測試的目地,在實際應用中TYPE應指定為session 或者select


METHOD:1)basic---僅僅在FAILOVER發生時才連線備用節點

2)preconnect---在使用者連線到主節點時同時也在備用節點產生一個連線會話,設定預連線模式,能夠快速接管SQL


RETRIES:當前節點失敗後,失敗切換功能會嘗試連線備用節點,這個值確定了嘗試的次數,如果僅DELAY被指定,RETRIES預設為5


DELAY:兩次嘗試之間等待的秒數,如果僅指定RETRIES,DELAY預設為1秒


BACKUP:指定另外一個用於備份連線的網路服務名,當RAC設定為主次模式時,使用此引數,並且METHOD應該設為preconnect


如果要使用預連線,就不能使用客戶端負載均衡和伺服器端負載均衡,否則沒有意義!!!


具有客戶端負載均衡及透明應用切換無預連線的tnsnames配置


RAC9I =

(DESCRIPTION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = tcp)(HOST = rac9iaw)(PORT = 1521))

(ADDRESS = (PROTOCOL = tcp)(HOST = rac9ibw)(PORT = 1521))

(LOAD_BALANCE = ON)

(FAILOVER = ON)

)

(CONNECT_DATA =

(SERVICE_NAME = rac9i.xyf)

(FAILOVER_MODE =

(TYPE = select)

(METHOD = basic)

(RETRIES = 10)

(DELAY = 1)

)

)

)

 

無客戶端負載均衡有透明應用切換且有預連線的tnsnames配置


RAC9I1 =

(DEscrīptION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = tcp)(HOST = rac9iaw)(PORT = 1521))

(LOAD_BALANCE = OFF)

(FAILOVER = ON)

)

(CONNECT_DATA =

(SERVICE_NAME = rac9i.xyf)

(INSTANCE_NAME = rac9i1)

(FAILOVER_MODE =

(BACKUP=RAC9I2)

(TYPE = select)

(METHOD = preconnect)

)

)

)

 

RAC9I2 =

(DEscrīptION =

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL = tcp)(HOST = rac9ibw)(PORT = 1521))

(LOAD_BALANCE = OFF)

(FAILOVER = ON)

)

(CONNECT_DATA =

(SERVICE_NAME = rac9i.xyf)

(INSTANCE_NAME = rac9i2)

(FAILOVER_MODE =

(BACKUP=RAC9I1)

(TYPE = select)

(METHOD = preconnect)

)

)

)


RAC設定為主次模式時的tnsnames配置

無客戶端負載均衡(主次模式就不要客戶端負載均衡了),有透明應用切換且有預連線的tnsnames配置

RAC9I1 =

(DEscrīptION =

(ADDRESS = (PROTOCOL = tcp)(HOST = rac9iaw)(PORT = 1521))

(ADDRESS = (PROTOCOL = tcp)(HOST = rac9ibw)(PORT = 1521))

(LOAD_BALANCE = OFF)

(FAILOVER = ON)

(CONNECT_DATA =

(SERVICE_NAME = rac9i.xyf)

(INSTANCE_ROLE = PRIMARY)

(INSTANCE_NAME = rac9i1)

(FAILOVER_MODE =

(BACKUP=RAC9I2)

(TYPE = select)

(METHOD = preconnect)

)

)

)


RAC9I2 =

(DEscrīptION =

(ADDRESS = (PROTOCOL = tcp)(HOST = rac9ibw)(PORT = 1521))

(ADDRESS = (PROTOCOL = tcp)(HOST = rac9iaw)(PORT = 1521))

(LOAD_BALANCE = OFF)

(FAILOVER = ON)

(CONNECT_DATA =

(SERVICE_NAME = rac9i.xyf)

(INSTANCE_ROLE = SECONDARY)

(INSTANCE_NAME = rac9i2)

(FAILOVER_MODE =

(BACKUP=RAC9I1)

(TYPE = select)

(METHOD = preconnect)

)

)

)


也可以設定為有透明應用切換但無預連線的模式,只要把上面的設定中的METHOD設定為basic。


與雙主模式時的配置相比,多了INSTANCE_ROLE這樣一個引數,當這個引數為SECONDARY時,這個本地服務命名不直接接收連線,只在主節點失敗後才會接收連線。不直接接收連線,並不是指在客戶端不能連通這個服務命名,只不過這個連線會被路由到主節點,次要次點並不真正有連線連上去。


自動切換特性是OCI8的內在特性,以下表格列出對TAF的support status

Application or Tool
 Earliest release with TAF Support
 
Oracle Call Interface (Oracle Call Interface)
Release 8
 Release 8
 
ODBC driver
 Release 8.0.5
 
JDBC driver
 Release 8.1.5 (thick driver only)
 
Pro* Pre-compilers
 Release 8.0.6 for transparent reconnect
Release 8.1.5 for full transparent functionality
 
SQL*Plus
 Release 8.0.4
 
Oracle Objects™ for OLE
 Release 8i
 

 

測試


> sqlplus


SQL*Plus: Release 9.0.1.3.0 - Production on Thu Jun 6 19:44:57 2002

(c) Copyright 2001 Oracle Corporation. All rights reserved.


Connected to:

Oracle9i Enterprise Edition Release 9.0.1.3.0 - 64bit Production

With the Partitioning and Real Application Clusters options

JServer Release 9.0.1.3.0 - Production


SQL> col sid format 999

SQL> col serial# format 9999999

SQL> col failover_type format a13

SQL> col failover_method format a15

SQL> col failed_over format a11

SQL> select sid, serial#, failover_type, failover_method, failed_over

from v$session where username = 'SU';


SID SERIAL# FAILOVER_TYPE FAILOVER_METHOD FAILED_OVER

---------- ---------- ------------- --------------- -----------

13 8 SELECT BASIC NO


If you see NONE under failover_type and failover_method, STOP!! You need

to fix your tnsnames.ora file, it does not make sense to continue to test

'shutdown abort' or reboot server.


SQL> select instance_name from v$instance;

INSTANCE_NAME

----------------

rac4


*** Due to the load balancing, we need to find out which instance it currently connects to. Now, we can continue our TAF testing.


SQL> select count(*) from

(select * from dba_source

union

select * from dba_source

union

select * from dba_source

union

select * from dba_source

union

select * from dba_source)

/


*** At this point, I ‘shutdown abort’ rac4 from another window. The query

did not stop and the result should be back.


COUNT(*)

----------

60221


*** The query results is back without any error.


SQL> col sid format 999

SQL> col serial# format 9999999

SQL> col failover_type format a13

SQL> col failover_method format a15

SQL> col failed_over format a11

SQL> select sid, serial#, failover_type, failover_method, failed_over

from v$session where username = 'SU';


SID SERIAL# FAILOVER_TYPE FAILOVER_METHOD FAILED_OVER

---------- ---------- ------------- --------------- -----------

13 5 SELECT BASIC YES


SQL> select instance_name from v$instance;

INSTANCE_NAME

----------------

rac1


*** Note here, it failed over to rac1 with different serial# and

failed_over flag was set.


Restarted rac4, make this database back to 4 instances database.


SQL> select count(*) from

(select * from dba_source

union

select * from dba_source

union

select * from dba_source

union

select * from dba_source

union

select * from dba_source)

/


*** At this point, I ‘shutdown abort’ rac1 from another window. The query

did not stop and the result should be back.

 

COUNT(*)

----------

60221

The query results is back without any error.


SQL>

SID SERIAL# FAILOVER_TYPE FAILOVER_METHOD FAILED_OVER

---------- ---------- ------------- --------------- -----------

14 20 SELECT BASIC YES


SQL> select instance_name from v$instance;

INSTANCE_NAME

----------------

rac2


*** Note here, it failed over to rac2 with different sid, serial# and

failed_over flag was set.

 

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

相關文章