Home:ALL Converter>FlywaySqlException on PostgreSQL : Cannot create PoolableConnectionFactory (ERROR: canceling statement due to user request

FlywaySqlException on PostgreSQL : Cannot create PoolableConnectionFactory (ERROR: canceling statement due to user request

Ask Time:2019-11-14T20:12:22         Author:JeyJ

Json Formatter

When my microservice is starting I'm using Flyway in order to create/update the schema. In some cases when I start the service I get the following exception :

Caused by: java.sql.SQLException: Cannot create PoolableConnectionFactory (ERROR: canceling statement due to user request)
    at org.apache.commons.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:2294) ~[commons-dbcp2-2.1.1.jar:2.1.1]
    at org.apache.commons.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:2039) ~[commons-dbcp2-2.1.1.jar:2.1.1]
    at org.apache.commons.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1533) ~[commons-dbcp2-2.1.1.jar:2.1.1]
    at org.flywaydb.core.internal.jdbc.JdbcUtils.openConnection(JdbcUtils.java:56) ~[flyway-core-5.2.1.jar:na]
    ... 37 common frames omitted
Caused by: org.postgresql.util.PSQLException: ERROR: canceling statement due to user request

I checked my Postgres (9.6) log and I saw my validation query and the error:

2019-11-13 20:47:49 IST batch 31002  ERROR:  canceling statement due to user request
2019-11-13 20:47:49 IST batch 31002  STATEMENT:  select 1 as test

I went over the BasicDataSource and the Java error is raised in the func validateConnectionFactory(connectionFactory). I'm not sure why but the validation query I'm using (select 1 as test) is failing. My ValidationQueryTimeout is set to 2.

I'm guessing that the validation query is taking more time because I tried to use another validation query as a test (select pg_sleep(10)) and I got the exact same error. Any chance that the db is killing this connection? My system doesn't have big load and it seems that during this flow it is idle so resources aren't the problem.

Author:JeyJ,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58856519/flywaysqlexception-on-postgresql-cannot-create-poolableconnectionfactory-erro
yy