1

Our web application is running on postgres 9.3 and Grails 2.5.3. When we restart postgres (/etc/init.d/postgresql restart) and access the website the exception "This connection has been closed." until we restart the grails app.

However, we would like the grails app to automatically reestablish a connection with the db, after we have restarted postgres. So we would like the app to automatically reconnect to the db by itself, without us having to restart the grails app.

Is that possible and if so how?

frasen
  • 169
  • 2
  • 6
  • 1
    How does your connection config look like right now? Did you try `testOnBorrow` and `validationQuery` parameters? – Michal_Szulc Apr 13 '16 at 09:57
  • Yes, these do solve the problem. I have just one question regarding testOnBorrow. Lets assume there is only one connection at a time, so the pool size is set to maxActive=maxIdle=minIdle=initialSize=1 and the connection is always in use because of heavy traffic. If the database is being rebooted/restarted, will this still work? I mean, because the connection may never return to the pool, because of the heavy load. Or is that nonsense? Another question: Why/when would I use testWhileIdle/testOnReturn instead? – frasen Apr 13 '16 at 13:50

1 Answers1

0

Check out this answer: https://stackoverflow.com/a/32437524/2166188 and add to config:

testOnBorrow=true
validationQuery=SELECT 1
Community
  • 1
  • 1
Michal_Szulc
  • 4,097
  • 6
  • 32
  • 59