I run a query against PostgreSQL DB using jOOQ. Since I know this query will take a long time, I try to set the query timeout. I tried several ways, but each time the result is that the query timeout is ignored and the query fails after a minute (which is the default timeout for this DB) with the error: "canceling statement due to statement timeout". Why is this, and how can I set the query timeout?
Here are the ways I tried to set the TO:
1.
DSL.using(dataSource, SQLDialect.POSTGRES, new Settings().withQueryTimeout(600))
.deleteFrom(...)
...
.execute();
DSL.using(dataSource, SQLDialect.POSTGRES)
.deleteFrom(...)
...
.queryTimeout(6000)
.execute();
DSLContext transactionContext =
DSL.using(dataSource, SQLDialect.POSTGRES, new Settings().withQueryTimeout(600));
transactionContext.transaction(configuration ->
{
DSL.using(configuration).deleteFrom(...)
...
.execute();
});
I was told that this is not related to jOOQ, so I made the following test:
import org.apache.commons.dbcp2.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
...
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(dbURL, username, password);
Connection connection = connectionFactory.createConnection();
PreparedStatement preparedStatement = connection.prepareStatement("select pg_sleep(80)");
preparedStatement.setQueryTimeout(120);
preparedStatement.execute();
This fails after a minute with the same timeout error, so the problem is indeed not related to jOOQ.
connection
is of type org.postgresql.jdbc.PgConnection
.
preparedStatement
is of type org.postgresql.jdbc.PgPreparedStatement
.