通过JDBC执行批量查询到pgbouncer时,我收到以下错误:
org.postgresql.util.PSQLException: ERROR: prepared statement "S_1" already exists
Run Code Online (Sandbox Code Playgroud)
我在网上发现了bug报告,但它们似乎都处理Postgres 8.3或更低版本,而我们正在使用Postgres 9.
这是触发错误的代码:
this.getJdbcTemplate().update("delete from xx where username = ?", username);
this.getJdbcTemplate().batchUpdate( "INSERT INTO xx(a, b, c, d, e) " +
"VALUES (?, ?, ?, ?, ?)", new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
ps.setString(1, value1);
ps.setString(2, value2);
ps.setString(3, value3);
ps.setString(4, value4);
ps.setBoolean(5, value5);
}
@Override
public int getBatchSize() {
return something();
}
});
Run Code Online (Sandbox Code Playgroud)
有人见过这个吗?
编辑1:
这被证明是在使用会话池以外的任何东西时发生的pgBouncer问题.我们使用的是事务池,显然不支持预准备语句.通过切换到会话池,我们解决了这个问题.
不幸的是,这不是我们用例的好方法.我们对pgBouncer有两个单独的用途:我们系统的一部分进行批量更新,这些更新作为预处理语句最有效,另一部分需要非常快速连续的许多连接.由于pgBouncer不允许在会话池 …