【发布时间】:2017-05-04 13:34:02
【问题描述】:
我正在使用 Java 和 Node Js 处理 redshift。不久前发现未在所有关闭连接调用上创建断开事件。 Java(使用 redshift.jdbc41 ):
Connection conn = null;
Statement stmt = null;
try {
...
} catch (Exception ex){
throw new Exception("Can't sync raw data from redshift");
}finally {
try {
if (stmt != null) {
stmt.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
和Node Js(使用pg模块)示例:
var client = new pg.Client(conString);
client.connect(function (err) {
if (err) throw err;
client.query(query, function (err, result) {
client.end(function (err) {if (err) throw err;});
...
});
});
所以在执行查询后调用代码关闭连接,但在 stl_connection_log 中为部分连接创建了仅 initiating session 事件,但没有 disconnecting session,因此许多连接保持活跃数天,并且在客户端应用程序停止后不会重置。
有人可以建议如何解决这个问题吗?可能需要为 redshift 或客户端应用程序中的其他工作方式进行一些配置?
【问题讨论】:
-
您可以在连接字符串中设置 idleTimeoutMillis:。
标签: java node.js amazon-redshift connectivity