1

I added setMaxActive(8) on org.apache.tomcat.jdbc.pool.PoolProperties. Every time the DB restarts, the application is unusable because the established connections remain. I get the following error:

org.postgresql.util.PSQLException: This connection has been closed

I've tried using some other settings on the pool to no avail...

Thank you for help!

Glenn
  • 8,932
  • 2
  • 41
  • 54

2 Answers2

1

Use the validationQuery property which will check if the connection is valid before returning the connection.

Ref: Tomcat 6 JDBC Connection Pool

This property is available on latest tomcat versions.

Community
  • 1
  • 1
James Jithin
  • 10,183
  • 5
  • 36
  • 51
1

Look at this link:

Postgres connection has been closed error in Spring Boot

Very valid question and this problem is usually faced by many. The exception generally occurs, when network connection is lost between pool and database (most of the time due to restart). Looking at the stack trace you have specified, it is quite clear that you are using jdbc pool to get the connection. JDBC pool has options to fine-tune various connection pool settings and log details about whats going on inside pool.

You can refer to to detailed Apache documentation on pool configuration to specify abandon timeout

Check for removeAbandoned, removeAbandonedTimeout, logAbandoned parameters

Additionally you can make use of additional properties to further tighten the validation

Use testXXX and validationQuery for connection validity.

My own $0.02: use these two parameters:

validationQuery=<TEST SQL>
testOnBorrow=true
Community
  • 1
  • 1
paulsm4
  • 114,292
  • 17
  • 138
  • 190