Last active
May 25, 2021 18:21
-
-
Save carymrobbins/9413965c9d5da772da05fa16b0fc30e7 to your computer and use it in GitHub Desktop.
Setting statement_timeout for postgresql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> Class.forName("org.postgresql.Driver") | |
res0: Class[_] = class org.postgresql.Driver | |
scala> val props = new java.util.Properties | |
props: java.util.Properties = {} | |
scala> props.setProperty("user","vagrant") | |
res1: Object = null | |
scala> props.setProperty("password","vagrant") | |
res2: Object = null | |
scala> props.setProperty("statement_timeout", "1") | |
res4: Object = null | |
scala> props | |
res5: java.util.Properties = {statement_timeout=1, user=vagrant, password=vagrant} | |
scala> java.sql.DriverManager.getConnection("jdbc:postgresql://localhost/vagrant", props) | |
res6: java.sql.Connection = org.postgresql.jdbc4.Jdbc4Connection@32eb8dc1 | |
scala> implicit val c: java.sql.Connection = res6 | |
c: java.sql.Connection = org.postgresql.jdbc4.Jdbc4Connection@32eb8dc1 | |
scala> anorm.SQL("select count(*) from foo")().toList | |
res8: List[anorm.Row] = List(Row(ColumnName(.count,Some(count)): 8749099 as java.lang.Long)) | |
scala> anorm.SQL("set statement_timeout = 1").execute() | |
res11: Boolean = false | |
scala> anorm.SQL("select count(*) from foo")().toList | |
org.postgresql.util.PSQLException: ERROR: canceling statement due to statement timeout | |
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270) | |
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998) | |
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255) | |
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570) | |
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420) | |
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:305) | |
at anorm.Sql$class.resultSet(Anorm.scala:286) | |
at anorm.SqlQuery.resultSet(Anorm.scala:384) | |
at anorm.Sql$class.apply(Anorm.scala:281) | |
at anorm.SqlQuery.apply(Anorm.scala:384) | |
... 43 elided |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment