Oracle RAC中,除了基于客户端的TAF方式之外,还有基于服务器端的TAF方式,可以把服务端的TAF方式看作是客户端TAF方式的一个升级版吧。服务器端的TAF,当然是需要在服务器端进行配置了,这个是通过Service来完成的。本文主要描述Oracle 10g rac 下通过service方式配置服务器端的TAF。
1、服务器端、客户端的环境
#服务器端环境,host信息
oracle@bo2dbp:~> cat /etc/hosts |grep vip
192.168.7.61 bo2dbp-vip.2gotrade.com bo2dbp-vip
192.168.7.62 bo2dbs-vip.2gotrade.com bo2dbs-vip
#服务器端环境,集群信息
oracle@bo2dbp:~> ./crs_stat.sh
Resource name Target State
-------------- ------ -----
ora.GOBO4.GOBO4A.inst ONLINE ONLINE on bo2dbp
ora.GOBO4.GOBO4B.inst ONLINE ONLINE on bo2dbs
ora.GOBO4.db ONLINE ONLINE on bo2dbp
ora.bo2dbp.ASM1.asm ONLINE ONLINE on bo2dbp
ora.bo2dbp.LISTENER_BO2DBP.lsnr ONLINE ONLINE on bo2dbp
ora.bo2dbp.LISTENER_ORA10G_BO2DBP.lsnr ONLINE ONLINE on bo2dbp
ora.bo2dbp.gsd ONLINE ONLINE on bo2dbp
ora.bo2dbp.ons ONLINE ONLINE on bo2dbp
ora.bo2dbp.vip ONLINE ONLINE on bo2dbp
ora.bo2dbs.ASM2.asm ONLINE ONLINE on bo2dbs
ora.bo2dbs.LISTENER_BO2DBS.lsnr ONLINE ONLINE on bo2dbs
ora.bo2dbs.LISTENER_ORA10G_BO2DBS.lsnr ONLINE ONLINE on bo2dbs
ora.bo2dbs.gsd ONLINE ONLINE on bo2dbs
ora.bo2dbs.ons ONLINE ONLINE on bo2dbs
ora.bo2dbs.vip ONLINE ONLINE on bo2dbs
ora.ora10g.db ONLINE ONLINE on bo2dbp
#客户端环境
robin@SZDB:~> cat /etc/issue
Welcome to SUSE Linux Enterprise Server 10 SP3 (x86_64) - Kernel \r (\l).
robin@SZDB:~> sqlplus -v
SQL*Plus: Release 10.2.0.3.0 - Production
#客户端tnsnames配置
GOBO4 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.61)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.7.62)(PORT = 1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = TAF) #注意我们客户端的SERVICE_NAME,我们设置为TAF
)
)
2、在服务器端配置service
配置service有多种方式,如dbca,oem,srvctl命令行。下面直接以命令行方式配置
oracle@bo2dbp:~> srvctl add service -d GOBO4 -s TAF -r GOBO4A -a GOBO4B -P basic
oracle@bo2dbp:~> srvctl start service -d GOBO4 -s TAF
oracle@bo2dbp:~> ./crs_stat.sh | grep TAF
ora.GOBO4.TAF.GOBO4A.srv ONLINE ONLINE on bo2dbp
ora.GOBO4.TAF.cs ONLINE ONLINE on bo2dbp
oracle@bo2dbp:~> srvctl config service -d GOBO4 -a
TAF PREF: GOBO4A AVAIL: GOBO4B TAF: basic
oracle@bo2dbp:~> export ORACLE_SID=GOBO4A
oracle@bo2dbp:~> sqlplus / as sysdba
SQL*Plus: Release 10.2.0.3.0 - Production on Mon Dec 17 14:55:02 2012
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Release 10.2.0.3.0 - 64bit Production
With the Real Application Clusters option
SQL> show parameter service
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
service_names string SYS$SYS.KUPC$S_1_2012102317304
4.GOBO4, SYS$SYS.KUPC$C_1_2012
1023173044.GOBO4, GOBO4, TAF
SQL> begin
2 dbms_service.modify_service(
3 service_name=>'TAF',
4 failover_method =>dbms_service.failover_method_basic,
5 failover_type =>dbms_service.failover_type_select,
6 failover_retries =>180,
7 failover_delay=>5);
8 end;
9 /
PL/SQL procedure successfully completed.
SQL> select name,failover_method,failover_type,goal,clb_goal from dba_services
2 where name='TAF';
NAME FAILOVER_METHOD FAILOVER_TYPE GOAL CLB_G
-------------------- -------------------- --------------- ------------ -----
TAF BASIC SELECT LONG
SQL> ho lsnrctl status
..........
Service "TAF" has 1 instance(s).
Instance "GOBO4A", status READY, has 2 handler(s) for this service...
The command completed successfully
3、测试服务器端TAF
robin@SZDB:~> sqlplus fail_over/fail@gobo4
fail_over@GOBO4> get verify.sql
1 REM the following query is for TAF connection verification
2 col sid format 99999
3 col serial# format 9999999
4 col failover_type format a13
5 col failover_method format a15
6 col failed_over format a11
7 Prompt
8 Prompt Failover status for current user
9 Prompt ============================================
10 SELECT sid,
11 serial#,
12 failover_type,
13 failover_method,
14 failed_over
15 FROM v$session
16 WHERE username = 'FAIL_OVER';
17 REM the following query is for load balancing verification
18 col host_name format a20
19 Prompt
20 Prompt Current instance name and host name
21 Prompt ========================================
22* SELECT instance_name,host_name FROM v$instance;
23
#下面的连接查询中表明客户端当前连接到了节点bo2dbp,其实例名为GOBO4A
fail_over@GOBO4> @verify
Failover status for current user
============================================
SID SERIAL# FAILOVER_TYPE FAILOVER_METHOD FAILED_OVER
------ -------- ------------- --------------- -----------
1073 48 SELECT BASIC NO
Current instance name and host name
========================================
INSTANCE_NAME HOST_NAME
---------------- --------------------
GOBO4A bo2dbp
#此时停止节点bo2dbp
oracle@bo2dbp:~> srvctl stop instance -d GOBO4 -i GOBO4A
#查看停止节点bo2dbp即实例GOBO4A后的结果
oracle@bo2dbp:~> ./crs_stat.sh |grep inst
ora.GOBO4.GOBO4A.inst OFFLINE OFFLINE
ora.GOBO4.GOBO4B.inst ONLINE ONLINE on bo2dbs
#此时回到客户端再次执行查询,FAILED_OVER的值已经变成YES,即表明当前的session为failover过来的
#同时实例名和节点名也发生了变化
fail_over@GOBO4> set timing on;
fail_over@GOBO4> @verify
Failover status for current user
============================================
SID SERIAL# FAILOVER_TYPE FAILOVER_METHOD FAILED_OVER
------ -------- ------------- --------------- -----------
1082 396 SELECT BASIC YES
Elapsed: 00:00:04.19
Current instance name and host name
========================================
INSTANCE_NAME HOST_NAME
---------------- --------------------
GOBO4B bo2dbs
Elapsed: 00:00:00.01
4、小结
a、服务器端的TAF方式的failover通过在服务器端配置service来完成
b、服务器端的TAF方式与客户端的TAF方式产生同样的效果
b、一旦在服务端配置了基于服务器端的TAF,客户端再无需通过在客户端添加FAILOVER_MODE项
c、该方式简化客户端配置,通过集中统一管理service实现failover
oracle视频教程请关注:http://u.youku.com/user_video/id_UMzAzMjkxMjE2.html