Redshift连接偶尔会掉线

时间:2018-10-17 10:43:49

标签: java spring-boot jdbc amazon-redshift aws-java-sdk

我正在使用redshift jdbc驱动程序连接到redshift集群,但是一段时间后连接断开。我将tcpKeepAlive设置为1分钟,但这也无济于事。

这是我得到的例外:

      java.sql.SQLException: [Amazon](500150) Error setting/closing 
      connection: Not Connected.

这是连接bean:

       @Bean(name="redShiftConn")
      public Connection connRedShift() {
         Connection conn = null;
       try{
         Class.forName("com.amazon.redshift.jdbc42.Driver");
        //Open a connection and define properties.
         System.out.println("Connecting to database...");
         Properties props = new Properties();
         props.setProperty("user", user);
         props.setProperty("password", password);
         props.setProperty("tcpKeepAlive", "true");
         props.setProperty("TCPKeepAliveMinutes", "1");
         props.setProperty("ssl", "true");
         props.setProperty("sslfactory", 
         "com.amazon.redshift.ssl.NonValidatingFactory");
        conn =DriverManager.getConnection("jdbc:redshift://"+endpoint+":"+port+"/"+database, props);
       return conn;
     }catch(Exception e) {
        System.out.println(e.toString());
    }
    return conn;
}

以下是Maven依赖项:

    <dependency>
         <groupId>com.amazon.redshift</groupId>
        <artifactId>redshift-jdbc42-no-awssdk</artifactId>
        <version>1.2.10.1009</version>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-core</artifactId>
        <version>1.11.118</version>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-redshift</artifactId>
        <version>1.11.118</version>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-sts</artifactId>
        <version>1.11.118</version>
        <scope>runtime</scope>
        <optional>true</optional>
    </dependency>

1 个答案:

答案 0 :(得分:0)

收到完全相同的错误消息。

我查看了Redshift Events,并在收到异常消息的同时(大约5分钟的延迟)注意到了这3条消息:

  • Cluster 'my-cluster' began restart at 2019-01-23 15:56 UTC. We will attempt to park database connections for the duration of the restart.
  • Amazon Redshift rebooted cluster my-cluster at 2019-01-23 15:56 UTC
  • Cluster 'my-cluster' completed restart at 2019-01-23 15:57 UTC.

然后,我查看了集群的CPU利用率,并以100%的利用率运行了几个小时(实际上,我正在运行2个消耗大量资源的进程写入Redshift)。通过查看AWS论坛中的this讨论,像这样

  

这些健康检查失败通常是由于群集负载过大或网络间歇性错误

就我而言,问题是工作量很大,导致群集无响应->自动重启-> java.sql.SQLException: [Amazon](500150) Error setting/closing connection: Not Connected.