【问题标题】:Redshift connection occasionally dropsRedshift 连接偶尔会掉线
【发布时间】:2019-03-22 00:33:35
【问题描述】:

我正在使用 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>

【问题讨论】:

  • 连接断开时会出现什么异常?
  • 这是我得到的异常:java.sql.SQLException: [Amazon](500150) 设置/关闭连接时出错:未连接。
  • 请将完整的异常堆栈跟踪添加到您的问题中
  • 这就是我要回来的全部内容。
  • 那是因为你用System.out.println(e.toString()),改用e.printStackTrace()

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


【解决方案1】:

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

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

  • 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.

【讨论】:

    猜你喜欢
    • 2015-03-14
    • 2021-02-14
    • 2018-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    相关资源
    最近更新 更多