[ACCEPTED]-JDBC postgres query with a timeout-jdbc
Accepted answer
The "statement_timeout" looks like what you want.
SET statement_timeout TO 1000; -- for a second
<your_query_here>;
RESET statement_timeout; -- reset
0
One way might be to try running the query 4 in a Timer class. Throw an exception 3 if the Timer ends without a value returned.
Hibernate and 2 JDO supply such a construct. Maybe they'd 1 be good alternatives for you.
Using the LOCAL keyword limits the scope 3 of the statement_timeout to the current transaction. That 2 way, if anything goes wrong (e.g. it times 1 out) the timeout gets reset.
BEGIN TRANSACTION;
SET LOCAL statement_timeout TO 1000; -- one-second timeout
SELECT COUNT(*) FROM really_huge_table; -- your slow query
ROLLBACK; -- reset
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.