TAF(Transparent
Application Failover)即透明应用程序故障转移技术。当初始化连接出现问题无法连接时,该功能可以保证应用程序重新连接到可用服务。在重新连接过程中,之前的活动事务将会被回滚,但在“具体条件”下TAF可以保证SELECT语句不被终止。这也是RAC亮点之一。
本文给出使用Oracle RAC的TAF技术实现不间断查询。
1.在tnsnames.ora文件中添加测试连接串
RACDB1@rac1 /home/oracle$ vi $ORACLE_HOME/network/admin/tnsnames.ora
testractaf =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT =
1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT =
1521))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = RACDB)
(FAILOVER_MODE =
(TYPE = SELECT)
(METHOD = BASIC)
(RETRIES = 180)
(DELAY = 5)
)
)
)
所谓的“具体条件”指的就是FAILOVER_MODE中METHOD选择“BASIC”、TYPE选择“SELECT”。
2.使用testractaf连接串连接到数据库
RACDB1@rac1 /home/oracle$ sqlplus sec/sec@testractaf
SQL*Plus: Release 10.2.0.1.0 - Production on Sun Oct
24 19:21:35 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
- Production
With the Partitioning, Real Application Clusters, OLAP
and Data Mining options
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
RACDB1
可见,此时sqlplus连接到了RAC的第一个实例RACDB1上。
3.手工停止RACDB1实例
[root@rac2 ~]# srvctl stop instance -d RACDB -i RACDB1
4.重新确认查询语句所在实例
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
RACDB2
注意观察,此时的查询语句没有报出任何错误。结果表明,此时sqlplus已经顺利的连接到了RAC的第二个实例RACDB2上。
5.恢复实例RACDB1,继续
[root@rac2 ~]# srvctl start instance -d RACDB -i RACDB1
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
RACDB2
6.此处我们模拟一个长时间无法返回全部信息的查询语句
SQL> select * from all_objects a,all_objects b,all_objects
c where a.object_id=b.object_id and a.object_id=c.object_id;
…… 此处省略输出信息 ……
7.手工停止RACDB2实例
[root@rac2 ~]# crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....B1.inst application ONLINE ONLINE rac1
ora....B2.inst application ONLINE ONLINE rac2
ora.RACDB.db application ONLINE ONLINE rac2
ora....DB1.srv application ONLINE ONLINE rac1
ora....DB2.srv application ONLINE ONLINE rac2
ora.....taf.cs application ONLINE ONLINE rac1
ora....SM1.asm application ONLINE ONLINE rac1
ora....C1.lsnr application ONLINE ONLINE rac1
ora.rac1.gsd application ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip application ONLINE ONLINE rac1
ora....SM2.asm application ONLINE ONLINE rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2
[root@rac2 ~]# srvctl stop instance -d RACDB -i RACDB2
[root@rac2 ~]# crs_stat -t
Name Type Target State Host
------------------------------------------------------------
ora....B1.inst application ONLINE ONLINE rac1
ora....B2.inst application OFFLINE OFFLINE
ora.RACDB.db application ONLINE ONLINE rac2
ora....DB1.srv application ONLINE ONLINE rac1
ora....DB2.srv application ONLINE OFFLINE
ora.....taf.cs application ONLINE ONLINE rac1
ora....SM1.asm application ONLINE ONLINE rac1
ora....C1.lsnr application ONLINE ONLINE rac1
ora.rac1.gsd application ONLINE ONLINE rac1
ora.rac1.ons application ONLINE ONLINE rac1
ora.rac1.vip application ONLINE ONLINE rac1
ora....SM2.asm application ONLINE ONLINE rac2
ora....C2.lsnr application ONLINE ONLINE rac2
ora.rac2.gsd application ONLINE ONLINE rac2
ora.rac2.ons application ONLINE ONLINE rac2
ora.rac2.vip application ONLINE ONLINE rac2
8.结论
注意观察sqlplus窗口中不间断的结果输出,在RACDB2实例中断过程中,可以看到输出结果在短暂的停顿后重新恢复输出,没有报错。这便是TAF带给我们的技术特性。
在手工“Ctrl + C”取消屏幕输出后可以观察到此时sqlplus已经连接到RACDB1实例。
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
RACDB1
9.小结
本文给出了在FAILOVER_MODE中METHOD选择“BASIC”、TYPE选择“SELECT”时,使用Oracle的TAF技术在RAC环境下实现SELECT语句不间断输出的例子。在实际应用中可以考虑使用该技术,保证查询语句不因实例故障而中断。
Good luck.
secooler
|