七、简单测试
(一)测试failover
客户端tns添加如下内容:
rac =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = zhh1-vip)(PORT = 3173))
(ADDRESS = (PROTOCOL = TCP)(HOST = zhh2-vip)(PORT = 3173))
(LOAD_BALANCE = yes)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = rac)
(FAILOVER_MODE =
(TYPE = select)
(METHOD =basic)
(RETRIES = 180)
(DELAY = 5)
)
)
)
1、客户端连接到rac上,查询连接的实例
C:\Documents and Settings\huizheng>sqlplus sys/sys@rac as sysdba
SQL*Plus: Release 11.1.0.6.0 - Production on 星期一 1月 3 15:00:49 2011
Copyright (c) 1982, 2007, Oracle. All rights reserved.
连接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
rac2
2、强制关闭上面session连接的实例rac2
[oracle@zhh2 ~]$ sqlplus / as sysdba
SQL*Plus: Release 10.2.0.5.0 - Production on 星期一 1月 3 15:03:06 2011
Copyright (c) 1982, 2010, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit Production
With the Partitioning, Real Application Clusters, OLAP, Data Mining
and Real Application Testing options
SQL> shutdown abort
ORACLE instance shut down.
3、查询当前连接的实例:rac1
SQL> select instance_name from v$instance;
INSTANCE_NAME
----------------
rac1
可以看到session会转移到rac1上了。
(二)、测试loadbalance
这里我们采用张晓明的例子。
准备两个脚本,一个是Shell脚本test.sh,另一个是SQL脚本test.sql
1、test.sh的内容
#!/bin/bash
count=0
while [ $count -lt $2 ]
do
count=`expr $count + 1`
sqlplus -s system/sys@$1 @test.sql
sleep 1
done
2、test.sql的内容
col "Instance_name" format a20
select instance_name from v$instance
/
3、执行
sh test.sh rac 60
4、查看执行结果
SQL> select inst_id,count(*) from gv$session
2 group by inst_id;
INST_ID COUNT(*)
---------- ----------
1 31
2 29
可以看出基本上两个实例的负载分配权重为1:1,需要注意的是这种分配并不是简单的算术平均。
浙公网安备 33010602011771号