我正在尝试通过在Java中运行以下SQL指令来吸尘我的Postgres数据库:

真空冗长分析

有时似乎只是“挂”有什么干净的流产方法?我努力了

将STACTER_TIMEOUT设置为xxxx

但是我收到错误消息“交易块内部无法运行的真空”

有帮助吗?

解决方案

我刚刚测试了,“真空”确实荣誉“ 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)

也许您必须(临时)在连接上启用自动加入。

其他提示

如果Postgres Server花费大量时间来加载数据IE,则可能会发生此错误。

我认为除了重新启动数据库之外,没有其他好的(即安全)杀死该过程的好方法。我也不知道任何交易超时选项。

最好的解决方案是找出导致悬挂并解决该问题的原因。真空吸尘器可能正在等待交易锁释放。使用 pg_locks 查看是否是这种情况。如果您可以看到要锁定的资源,则可以开始解决该问题。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top