理論背景:
TAF( Transparent Application Failover ) allows oracle clients to reconnect to a surviving instance in the event of a failure of the instance to which it is connected. There are two types of TAF available, SESSION and SELECT.
TAF允許oracle用戶端重新連接配接到一個可持續的執行個體,當用戶端連接配接的執行個體出現失敗時。有2種有效的TAF類型,session and select 。有2種模式在TAF建立的故障轉移連接配接,basic 和preconnect 。
session: 使用session方式,所有select查詢相關的結果在重建立立新的連接配接後将全部丢失,需要重新釋出select指令。
select:select:使用select方式,Oracle net會跟蹤事務期間的所有select語句,并跟蹤每一個與目前select相關的遊标已傳回多少行給客戶 端。此時,假定select查詢已傳回500行,用戶端目前連接配接的節點出現故障,Oracle Net自動建立連接配接到幸存的執行個體上并繼續傳回剩餘的行數給用戶端。假定總行數為1500,行,則1000行從剩餘節點傳回。
BASIC: 用戶端通過位址清單成功建立連接配接後,即僅當用戶端感覺到節點故障時才建立到其他執行個體的連接配接
PRECONNECT: 預連接配接模式,是在最初建立連接配接時就同時建立到所有執行個體的連接配接,當發生故障時,立刻就可以切換到其他鍊路上
說明:上述兩種方式适用于不同的情形,對于select方式,通常使用與OLAP資料庫,而對于session方式則使用與OLTP資料庫。因為 select 方式,Oracle 必須為每個session儲存更多的内容,包括遊标,使用者上下文等,需要更多的資源。其次,兩種方式期間所有未送出的DML事務将自動復原且必須重新開機啟動。alter session語句不會failover。臨時對象不會failover也不能被重新啟動。
配置Service-Side TAF 示例 (oracle使用者操作)
1 建立TAF Service
node1-> pwd
/u01/app/11.2.0/grid/bin
node1-> ./srvctl add service -d devdb -s server_taf -r "devdb1" -P BASIC
說明:
Srvctl add service -d -s -r "preferred-instance-list" -a "available-instance-list" -P
srvctl add service中,隻有perferred才會建立服務。 即在OCR中注冊一個ora.raw.dmm.rac1.Srv的服務。
2 啟動 server_taf服務
node1-> ./srvctl start service -d devdb -s server_taf
3 檢查service 運作情況
node1-> ./srvctl config service -d devdb
Service name: server_taf
Service is enabled
Server pool: devdb_server_taf
Cardinality: 1
Disconnect: false
Service role: PRIMARY
Management policy: AUTOMATIC
DTP transaction: false
AQ HA notifications: false
Failover type: NONE
Failover method: NONE
TAF failover retries: 0
TAF failover delay: 0
Connection Load Balancing Goal: LONG
Runtime Load Balancing Goal: NONE
TAF policy specification: BASIC
Edition:
Preferred instances: devdb1
Available instances:
4 确認service ID
SQL> select name,service_id from dba_services where name = 'server_taf';
NAMESERVICE_ID
---------------------------------------------------------------- ----------
server_taf 3
5 給service 添加參數
SQL> execute dbms_service.modify_service (service_name => 'server_taf' -
, aq_ha_notifications => true -
, failover_method => dbms_service.failover_method_basic -
, failover_type => dbms_service.failover_type_select -
, failover_retries => 180 -
, failover_delay => 5 -
, clb_goal => dbms_service.clb_goal_long);
> > > > > >
PL/SQL procedure successfully completed.
6 确認參數修改
col name format a15
col failover_method format a11 heading 'METHOD'
col failover_type format a10 heading 'TYPE'
col failover_retries format 9999999 heading 'RETRIES'
col goal format a10
col clb_goal format a8
col AQ_HA_NOTIFICATIONS format a5 heading 'AQNOT'
SQL> select name, failover_method, failover_type, failover_retries,goal, clb_goal,aq_ha_notifications from dba_services where service_id = 3;
NAMEMETHOD TYPERETRIES GOAL CLB_GOAL AQNOT
--------------- ----------- ---------- -------- ---------- -------- -----
server_tafBASIC SELECT 180 NONE LONG YES
7 檢查service 注冊情況
node1-> lsnrctl services
LSNRCTL for Linux: Version 11.2.0.4.0 - Production on 26-FEB-2017 04:43:55
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
Services Summary...
Service "+ASM" has 1 instance(s).
Instance "+ASM1", status READY, has 1 handler(s) for this service...
Handler(s):
"DEDICATED" established:2 refused:0 state:ready
LOCAL SERVER
Service "devdb" has 1 instance(s).
Instance "devdb1", status READY, has 1 handler(s) for this service...
"DEDICATED" established:0 refused:0 state:ready
Service "devdbXDB" has 1 instance(s).
"D000" established:0 refused:0 current:0 max:1022 state:ready
DISPATCHER
(ADDRESS=(PROTOCOL=tcp)(HOST=node1.localdomain)(PORT=26677))
Service "server_taf" has 1 instance(s).
The command completed successfully
8 在用戶端就可以使用Service-Side TAF了
在用戶端TNS 配置:
server_taf =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = scan-cluster.localdomain)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = server_taf)
)
連接配接測試
C:\Users\andy>sqlplus sys/[email protected]:1521/server_taf as sysdba
SQL*Plus: Release 12.1.0.2.0 Production on Sat Feb 25 20:59:41 2017
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
9 停止service
node1-> ./srvctl stop service -d devdb -s server_taf -i devdb1
10 删除service
node1-> ./srvctl remove service -d devdb -s server_taf -i devdb1
\
本文轉自 張沖andy 部落格園部落格,原文連結: http://www.cnblogs.com/andy6/p/6442889.html ,如需轉載請自行聯系原作者