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