0

Is there a way to "cut down" jdbc call (commit or statement execution) to Postgres after specific timeout with millisecond accuracy?

JDBC driver docs propose loginTimeout, socketTimeout, connectTimeout, cancelSignalTimeout, statement_timeout, yet all of them but the latter have second accuracy.

JDBC Statement api propose setQueryTimeout, yet with second accuracy too.

statement_timeout alone "kinda" works - driver logs show some requests being timed out, yet client stats (tracing) show a lot of calls wait way too long, even when they are cancelled on server side.

Working (yet too lame) solution - calling Thread.interrupt() on jdbc thread (e.g. with some ScheduledExecutorService), hoping jdbc to send cancel signal on InterruptedException.

Asking for the advice, maybe smb got this working in more human way.

mrmirg
  • 53
  • 6
  • @jjanes I dont see such method in jdbc api. Also, even setQueryTimeout seems to be unimplemented in postgres jdbc driver specifically – mrmirg Mar 20 '23 at 16:37
  • @jjanes That I was considering, but with various tests and behaviour simulations got sure it is not a network issue. – mrmirg Mar 20 '23 at 16:44
  • And it is odd that there seem to be no way to set desired timeout in JDBC on client side. Curious why these settings have such low accuracy, are there any technical limitations justifying that. – mrmirg Mar 20 '23 at 16:53
  • 1
    setQueryTimeoutMs is a pgjdbc extension, it doesn't exist in the JDBC API itself. So you have to import org.postgresql.jdbc.PgStatement and then cast the statement to PgStatement to use it. I don't know the story behind JDBC API's choices, in my experience Java sucks in general, so I am not surprised that is sucks in particular as well. – jjanes Mar 20 '23 at 18:22
  • In my tests, the server-side timeout works the way it should. Without knowing the details of your tests, I can't offer any other help there. – jjanes Mar 20 '23 at 18:34
  • @jjanes PgStatement may be worth checking out. Thanks for your responses. – mrmirg Mar 20 '23 at 19:20

0 Answers0