我正在尝试通过在 Java 中运行以下 SQL 指令来清理我的 Postgres 数据库:
真空详分割析
有时它似乎只是“挂起”有没有任何干净的方法来中止该过程?我试过了
将 statement_timeout 设置为 XXXX
但我收到错误消息“VACCUM 无法在事务 block 内运行”
最佳答案
我刚刚测试过,“vacuum”确实支持“statement_timeout”。示例程序:
import java.sql.*;
class test
{
public static void main(String[] args) {
try {
Class.forName("org.postgresql.Driver");
Connection connection =
DriverManager.getConnection(
"jdbc:postgresql://hostname/dbname",
"username",
"password"
);
connection.createStatement().executeUpdate(
"set statement_timeout to 500"
);
connection.createStatement().executeUpdate(
"vacuum analyze"
);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
我收到以下错误:
org.postgresql.util.PSQLException: ERROR: canceling statement due to statement timeout
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2062)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1795)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:479)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:353)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:299)
at test.main(test.java:14)
也许您必须(临时)在您的连接上启用自动提交。
关于postgresql - JDBC postgres 真空超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1281333/