VACUUM无法在事务块内运行

时间:2014-04-14 13:30:46

标签: postgresql jdbc

我的应用程序有以下代码:

Connection connection = DriverManager.getConnection(url, userName, password);
connection.setAutoCommit(false);
try {
    Statement statement = connection.createStatement();
    try {
        statement.executeUpdate("TRUNCATE mytable");
    } finally {
        statement.close();
    }
    connection.commit();
    connection.setAutoCommit(true);
    statement = connection.createStatement();
    try {
        statement.executeUpdate("VACUUM mytable");
    } finally {
        statement.close();
    }
    connection.setAutoCommit(false);
    connection.commit();
} finally {
    connection.close();
}

statement.executeUpdate("VACUUM mytable");VACUUM cannot run inside a transaction block而失败。

我必须遗漏一些概念,因为我认为将自动提交设置为true会删除事务上下文(TRUNCATE所需)。显然它没有。那么如何摆脱事务上下文并成功执行我的VACUUM?我应该如何编写代码以使其没有此事务上下文?

0 个答案:

没有答案