Home  >  Article  >  Database  >  Vertica7NativeConnectionLoadBalance

Vertica7NativeConnectionLoadBalance

WBOY
WBOYOriginal
2016-06-07 16:01:041184browse

原文链接:Vertica7 Native Connection Load Balance 在Vertica7以前的版本中,Vertica是通过Linux的Virtual IP来实现连接的负载均衡的,但是在Vertica7x中,Vertica本身提供了连接的负载均衡功能,这个功能用起来也是非常方便的,下面就来看看怎么使用这个

原文链接:Vertica7 Native Connection Load Balance

在Vertica7以前的版本中,Vertica是通过Linux的Virtual IP来实现连接的负载均衡的,但是在Vertica7x中,Vertica本身提供了连接的负载均衡功能,这个功能用起来也是非常方便的,下面就来看看怎么使用这个功能。 

1. 首先安装N个Vertica7的节点,然后用数据库管理员的身份运行下面的命令来让Vertica使用这个功能

SELECT SET_LOAD_BALANCE_POLICY('ROUNDROBIN');

SELECT SET_LOAD_BALANCE_POLICY('NONE');
SELECT GET_LOAD_BALANCE_POLICY();
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; public class VerticaTest { private static String USERNAME = "<user>"; private static String PASSWORD = "<password>"; private static String URL = "jdbc:vertica://<ip>:5433/<db>"; public static void main(String[] args) throws Exception { Class.forName("com.vertica.jdbc.Driver"); Properties props = new Properties(); props.put("user", USERNAME); props.put("password", PASSWORD); props.put("ConnectionLoadBalance", 1); for (int x = 1; x 
<pre class="brush:php;toolbar:false">
这里特别注意下面一句,这一句设置了一个连接属性告诉Vertica的JDBC驱动使用负载均衡功能。 
props.put("ConnectionLoadBalance", 1);
4. 测试

另外也可以通过下面的sql来查询当前所有连接的情况。

select node_name, client_hostname from sessions;
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn