postgresql error: canceling statement due to user request

后端 未结 4 1711
别那么骄傲
别那么骄傲 2020-12-25 13:00

What causes this error in postgresql?

org.postgresql.util.PSQLException: ERROR: canceling statement due to user request

4条回答
  •  臣服心动
    2020-12-25 13:26

    This assumes that the race condition bug in the jdbc jar file for postgresql is responsible for the above error. (race condition described here: http://postgresql.1045698.n5.nabble.com/ERROR-canceling-query-due-to-user-request-td2077761.html)

    Workaround 1, refresh connection to database periodically

    One workaround is to close the connection to the database and create a new connection to the database periodically. After every few thousand sql statements just close the connection and re-create it. Then for some reason this error is no longer thrown.

    Workaround 2, turn on logging

    If you turn on logging at the JDBC driver level when you are setting the driver, then in some situations the race condition problem is neutralized:

    Class.forName("org.postgresql.Driver");
    org.postgresql.Driver.setLogLevel(org.postgresql.Driver.DEBUG);
    

    Workaround 3, catch the exception and re-initialize connection

    You could also try catching the specific exception, re-initializing the connection and trying the query again.

    Workaround 4, wait until postgresql jdbc jar comes out with a bug fix

    I think the problem may be associated with the speed of my SSD hard drive. If you get this error, please post how to reproduce it consistently here, there are devs very interested in squashing this bug.

提交回复
热议问题