11.2的官方文档是这么写的
LOAD_BALANCE
Purpose
To enable or disable client load balancing for multiple protocol addresses.
When you set the parameter to on, yes, or true, Oracle Net progresses the list of addresses in a
random sequence, balancing the load on the various listener or Oracle Connection Manager protocol
addresses. When you set the parameter to off, no, or false, Oracle Net tries the first address in
the address list. If the connection fails and the failover parameter is enabled, then Oracle Net
tries the addresses sequentially until one succeeds.
Put this parameter under either the DESCRIPTION_LIST parameter, the
DESCRIPTION parameter, or the ADDRESS_LIST parameter.
Default
on for DESCRIPTION_LIST
但实际上经过我的实验发现,这个貌似并非如此。
orcl =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
实验步骤如下:
新建一个用户test
create user test identified by test;
grant dba to test;
编写一个shell
i=1
while(($i <100))
do
sqlplus test/test@orcl &
((i=$i+1))
done
另外起个会话监控
select inst_id,count(*) from gv$session where username='TEST' group by inst_id;
当不显式的加load_balance参数的时候,
发现
INST_ID COUNT(*)
---------- ----------
1 99
当tns变成下面的样子
orcl =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))
(load_balance=on)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
结果才变成
INST_ID COUNT(*)
---------- ----------
1 51
2 48
以前一直以为缺省是ON的,不用加就可以,事实证明好像不对。
后面又一想oracle大概不会有如此明显的错误,文档上是说on for DESCRIPTION_LIST,字面意思是使用DESCRIPTION_LIST的话是on。
真的是这样的吗?
改成下面的样子去试试:
orcl =
(description_list=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac1-vip)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = rac2-vip)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
)
发现再连果然是load balance了。
SQL> /
INST_ID COUNT(*)
---------- ----------
1 46
2 53
SQL>
还是自己不够细心啊。
总结一下:
load_balance参数缺省是off的,除非在description_list里面,而一般我们是不大会用description_list的。