发表于: 2007.04.23 17:37
分类: ORACLE
出处: http://yangtingkun.itpub.net/post/468/283068
---------------------------------------------------------------
Oracle的RAC的高可用功能除了负载均衡还包括TAF(Transparent Application Failover)。
RAC的TAF是指会话连接到一个实例上,如果这个实例出现了故障,Oracle会自动将会话迁移到另一个实例上。
看一个简单的例子。首先不配置TAF,在客户端TNSNAMES.ORA中进行如下的测试:
TESTRAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.224)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.225)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = testrac)
)
)
现在没有配置TAF,连接数据库,检查实例信息:
SQL> CONN NDMAIN/NDMAIN@TESTRAC已连接。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;
INSTANCE_NAME
----------------
testrac2
下面关闭TESTRAC2实例:
$ srvctl stop instance -d testrac -i testrac2
再次检查刚才连接的会话:
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;
SELECT INSTANCE_NAME FROM V$INSTANCE
*第 1 行出现错误:
ORA-03113: 通信通道的文件结束
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;
ERROR:
ORA-03114: 未连接到 ORALCE
执行操作后,Oracle会报上面的错误。下面启动服务,配置TAF:
TESTRAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.224)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.225)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = testrac)
(FAILOVER_MODE =
(TYPE = SESSION)
(METHOD = BASIC)
)
)
)
$ srvctl start instance -d testrac -i testrac2
重新登陆,检查实例信息:
SQL> CONN NDMAIN/NDMAIN@TESTRAC已连接。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;
INSTANCE_NAME
----------------
testrac1
再次关闭实例:
$ srvctl stop instance -d testrac -i testrac1
检查刚才的连接的会话:
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;
INSTANCE_NAME
----------------
testrac1
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;
SELECT INSTANCE_NAME FROM V$INSTANCE
*第 1 行出现错误:
ORA-25408: 无法安全重放调用
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;
INSTANCE_NAME
----------------
testrac2
虽然报了一个错误ORA-25408,但是再次执行的时候,Oracle已经自动切换到实例TESTRAC2上了。
启动TESTRAC1实例,然后关闭TESTRAC2实例:
$ srvctl start instance -d testrac -i testrac1
$ srvctl stop instance -d testrac -i testrac2
再次检查连接情况:
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;
SELECT INSTANCE_NAME FROM V$INSTANCE
*第 1 行出现错误:
ORA-25408: 无法安全重放调用
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;
INSTANCE_NAME
----------------
testrac1
Oracle成功的切换回testrac1实例。Oracle这里也存在一个问题,就是会产生ORA-25408错误。Oracle给出的解决方法是应用程序对这个错误进行处理。
如果将FAILOVER的TYPE改为SELECT模式,则也不会出现这个错误,首先修改TNSNAMES中的设置:
TESTRAC =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.224)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.25.198.225)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = testrac)
(FAILOVER_MODE =
(TYPE = SELECT)
(METHOD = BASIC)
)
)
)
然后启动刚才关闭的TESTRAC2实例:
$ srvctl start instance -d testrac -i testrac2
重新连接到实例:
SQL> CONN NDMAIN/NDMAIN@TESTRAC已连接。
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;
INSTANCE_NAME
----------------
testrac1
关闭TESTRAC1实例:
$ srvctl stop instance -d testrac -i testrac1
检查会话连接的情况:
SQL> SELECT INSTANCE_NAME FROM V$INSTANCE;
INSTANCE_NAME
----------------
testrac2
这时第一次执行SQL就成功了,没有在出现ORA-25408错误。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/110321/viewspace-614861/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/110321/viewspace-614861/