I've just tested and "vacuum" does honor "statement_timeout". Example program:
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();
}
}
}
I get the following error:
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)
Maybe you have to (temporary) enable autocommit on your connection.