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/binnode1-> ./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_taf3 检查service 运行情况
node1-> ./srvctl config service -d devdbService name: server_tafService is enabledServer pool: devdb_server_tafCardinality: 1Disconnect: falseService role: PRIMARYManagement policy: AUTOMATICDTP transaction: falseAQ HA notifications: falseFailover type: NONEFailover method: NONETAF failover retries: 0TAF failover delay: 0Connection Load Balancing Goal: LONGRuntime Load Balancing Goal: NONETAF policy specification: BASICEdition: Preferred instances: devdb1Available instances:4 确认service ID
SQL> select name,service_id from dba_services where name = 'server_taf'; NAMESERVICE_ID---------------------------------------------------------------- ----------server_taf 35 给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 YES7 检查service 注册情况
node1-> lsnrctl servicesLSNRCTL 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:readyLOCAL SERVERService "devdb" has 1 instance(s).Instance "devdb1", status READY, has 1 handler(s) for this service...Handler(s):"DEDICATED" established:0 refused:0 state:readyLOCAL SERVERService "devdbXDB" has 1 instance(s).Instance "devdb1", status READY, has 1 handler(s) for this service...Handler(s):"D000" established:0 refused:0 current:0 max:1022 state:readyDISPATCHER (ADDRESS=(PROTOCOL=tcp)(HOST=node1.localdomain)(PORT=26677))Service "server_taf" has 1 instance(s).Instance "devdb1", status READY, has 1 handler(s) for this service...Handler(s):"DEDICATED" established:0 refused:0 state:readyLOCAL SERVERThe command completed successfully8 在客户端就可以使用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/oracle@10.100.25.8:1521/server_taf as sysdbaSQL*Plus: Release 12.1.0.2.0 Production on Sat Feb 25 20:59:41 2017Copyright (c) 1982, 2014, Oracle. All rights reserved.Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionWith the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,Data Mining and Real Application Testing options9 停止service
node1-> ./srvctl stop service -d devdb -s server_taf -i devdb110 删除service
node1-> ./srvctl remove service -d devdb -s server_taf -i devdb1