title: Flyway stuck when cleaning database (Postgres 11)
body: <p>our application contains tests which are can't simple rollback. So we decide use flyway's java API for it. We added this method into test:</p>
  <pre><code>@AfterEach
  public void remigrate() {
      flyway.clean();
      flyway.migrate();
  }
  </code></pre>
  <p>In log I found only this:</p>
  <pre><code>2020-06-29 15:20:10.356 DEBUG  [-] 1044 --- [           main] o.f.c.i.s.classpath.ClassPathScanner     : Found resource: db/migration/V0_0_1__database-initialization.sql
  2020-06-29 15:20:10.356 DEBUG  [-] 1044 --- [           main] o.f.c.i.s.classpath.ClassPathScanner     : Scanning for classes at classpath:db/migration
  2020-06-29 15:20:10.356 DEBUG  [-] 1044 --- [           main] o.f.c.i.c.SqlScriptCallbackFactory       : Scanning for SQL callbacks ...
  2020-06-29 15:20:10.356 DEBUG  [-] 1044 --- [           main] o.f.core.internal.util.FeatureDetector   : Spring Jdbc available: true
  2020-06-29 15:20:10.361 DEBUG  [-] 1044 --- [           main] o.f.core.internal.command.DbClean        : Cleaning schema &quot;public&quot; ...
  </code></pre>
  <p>After this application stuck. When I tried to select flyway history table records, db client is only loading. Selects on other tables works fine, so I expected flyway creates deadlock on history table. Do you have idea how to fix it? Thank you.</p>
  <p>Last stacktraces from actuator's threaddump related to flyway's clean:</p>
  <pre><code>{
  methodName: &quot;socketRead0&quot;,
  fileName: &quot;SocketInputStream.java&quot;,
  lineNumber: -2,
  className: &quot;java.net.SocketInputStream&quot;,
  nativeMethod: true
  },
  {
  methodName: &quot;socketRead&quot;,
  fileName: &quot;SocketInputStream.java&quot;,
  lineNumber: 116,
  className: &quot;java.net.SocketInputStream&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;read&quot;,
  fileName: &quot;SocketInputStream.java&quot;,
  lineNumber: 171,
  className: &quot;java.net.SocketInputStream&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;read&quot;,
  fileName: &quot;SocketInputStream.java&quot;,
  lineNumber: 141,
  className: &quot;java.net.SocketInputStream&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;readMore&quot;,
  fileName: &quot;VisibleBufferedInputStream.java&quot;,
  lineNumber: 140,
  className: &quot;org.postgresql.core.VisibleBufferedInputStream&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;ensureBytes&quot;,
  fileName: &quot;VisibleBufferedInputStream.java&quot;,
  lineNumber: 109,
  className: &quot;org.postgresql.core.VisibleBufferedInputStream&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;read&quot;,
  fileName: &quot;VisibleBufferedInputStream.java&quot;,
  lineNumber: 67,
  className: &quot;org.postgresql.core.VisibleBufferedInputStream&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;receiveChar&quot;,
  fileName: &quot;PGStream.java&quot;,
  lineNumber: 321,
  className: &quot;org.postgresql.core.PGStream&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;processResults&quot;,
  fileName: &quot;QueryExecutorImpl.java&quot;,
  lineNumber: 1978,
  className: &quot;org.postgresql.core.v3.QueryExecutorImpl&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;execute&quot;,
  fileName: &quot;QueryExecutorImpl.java&quot;,
  lineNumber: 309,
  className: &quot;org.postgresql.core.v3.QueryExecutorImpl&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;executeInternal&quot;,
  fileName: &quot;PgStatement.java&quot;,
  lineNumber: 446,
  className: &quot;org.postgresql.jdbc.PgStatement&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;execute&quot;,
  fileName: &quot;PgStatement.java&quot;,
  lineNumber: 370,
  className: &quot;org.postgresql.jdbc.PgStatement&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;executeWithFlags&quot;,
  fileName: &quot;PgPreparedStatement.java&quot;,
  lineNumber: 149,
  className: &quot;org.postgresql.jdbc.PgPreparedStatement&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;execute&quot;,
  fileName: &quot;PgPreparedStatement.java&quot;,
  lineNumber: 138,
  className: &quot;org.postgresql.jdbc.PgPreparedStatement&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;execute&quot;,
  fileName: &quot;ProxyPreparedStatement.java&quot;,
  lineNumber: 44,
  className: &quot;com.zaxxer.hikari.pool.ProxyPreparedStatement&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;execute&quot;,
  fileName: &quot;HikariProxyPreparedStatement.java&quot;,
  lineNumber: -1,
  className: &quot;com.zaxxer.hikari.pool.HikariProxyPreparedStatement&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;invoke&quot;,
  fileName: null,
  lineNumber: -1,
  className: &quot;sun.reflect.GeneratedMethodAccessor103&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;invoke&quot;,
  fileName: &quot;DelegatingMethodAccessorImpl.java&quot;,
  lineNumber: 43,
  className: &quot;sun.reflect.DelegatingMethodAccessorImpl&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;invoke&quot;,
  fileName: &quot;Method.java&quot;,
  lineNumber: 498,
  className: &quot;java.lang.reflect.Method&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;doExecute&quot;,
  fileName: &quot;JdbcWrapper.java&quot;,
  lineNumber: 412,
  className: &quot;net.bull.javamelody.JdbcWrapper&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;invoke&quot;,
  fileName: &quot;JdbcWrapper.java&quot;,
  lineNumber: 137,
  className: &quot;net.bull.javamelody.JdbcWrapper$StatementInvocationHandler&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;invoke&quot;,
  fileName: &quot;JdbcWrapper.java&quot;,
  lineNumber: 294,
  className: &quot;net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;execute&quot;,
  fileName: null,
  lineNumber: -1,
  className: &quot;com.sun.proxy.$Proxy207&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;execute&quot;,
  fileName: &quot;JdbcTemplate.java&quot;,
  lineNumber: 215,
  className: &quot;org.flywaydb.core.internal.jdbc.JdbcTemplate&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;doDrop&quot;,
  fileName: &quot;PostgreSQLTable.java&quot;,
  lineNumber: 43,
  className: &quot;org.flywaydb.core.internal.database.postgresql.PostgreSQLTable&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;drop&quot;,
  fileName: &quot;SchemaObject.java&quot;,
  lineNumber: 81,
  className: &quot;org.flywaydb.core.internal.database.base.SchemaObject&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;doClean&quot;,
  fileName: &quot;PostgreSQLSchema.java&quot;,
  lineNumber: 97,
  className: &quot;org.flywaydb.core.internal.database.postgresql.PostgreSQLSchema&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;clean&quot;,
  fileName: &quot;Schema.java&quot;,
  lineNumber: 149,
  className: &quot;org.flywaydb.core.internal.database.base.Schema&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;call&quot;,
  fileName: &quot;DbClean.java&quot;,
  lineNumber: 172,
  className: &quot;org.flywaydb.core.internal.command.DbClean$3&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;call&quot;,
  fileName: &quot;DbClean.java&quot;,
  lineNumber: 169,
  className: &quot;org.flywaydb.core.internal.command.DbClean$3&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;execute&quot;,
  fileName: &quot;TransactionTemplate.java&quot;,
  lineNumber: 74,
  className: &quot;org.flywaydb.core.internal.jdbc.TransactionTemplate&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;cleanSchema&quot;,
  fileName: &quot;DbClean.java&quot;,
  lineNumber: 169,
  className: &quot;org.flywaydb.core.internal.command.DbClean&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;clean&quot;,
  fileName: &quot;DbClean.java&quot;,
  lineNumber: 113,
  className: &quot;org.flywaydb.core.internal.command.DbClean&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;doClean&quot;,
  fileName: &quot;Flyway.java&quot;,
  lineNumber: 1488,
  className: &quot;org.flywaydb.core.Flyway&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;access$300&quot;,
  fileName: &quot;Flyway.java&quot;,
  lineNumber: 85,
  className: &quot;org.flywaydb.core.Flyway&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;execute&quot;,
  fileName: &quot;Flyway.java&quot;,
  lineNumber: 1506,
  className: &quot;org.flywaydb.core.Flyway$3&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;execute&quot;,
  fileName: &quot;Flyway.java&quot;,
  lineNumber: 1499,
  className: &quot;org.flywaydb.core.Flyway$3&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;execute&quot;,
  fileName: &quot;Flyway.java&quot;,
  lineNumber: 1711,
  className: &quot;org.flywaydb.core.Flyway&quot;,
  nativeMethod: false
  },
  {
  methodName: &quot;clean&quot;,
  fileName: &quot;Flyway.java&quot;,
  lineNumber: 1499,
  className: &quot;org.flywaydb.core.Flyway&quot;,
  nativeMethod: false
  },
  </code></pre>