0

I'm using the Tomcat JDBC Connection Pool (which is the Spring Boot default) to manage connections to my PostgreSQL cluster, and I just noticed that the pool is created only when the very first query is made. My question is twofold:

  1. Is there any elegant way to force the pool to be created eagerly (ie, when starting the application)? I believe that executing a simple query upon startup would do the trick, but I'd prefer a more elegant way if available.
  2. During one of my tests I used iptables to drop all traffic directed at the PostgreSQL cluster. This caused the first query to last for about 127 seconds before failing with the message Unable to create initial connections of pool. 127 seconds is way too much. Is there any way I can set a lower value for the timeout? I've read the docs but could not conclude much.
Martin
  • 1,317
  • 3
  • 13
  • 18

1 Answers1

-1

Well, for your first question, I can only think 2 methods:

For your second question; if you choose second approach for first question, than it'll automatically resolved. But you can always set

spring.datasouce.max-wait

parameter. In the Tomcat Pool doc it says

(int) The maximum number of milliseconds that the pool will wait (when there are no available connections) for a connection to be returned before throwing an exception. Default value is 30000 (30 seconds)

but in your case, it's 127 seconds, which is strange..

Gokhan Oner
  • 3,237
  • 19
  • 25
  • That refers to DB initialization (schema creation and table population), not pool initialization. Also, providing `initSQL` does not, in any way, force the pool to be created eagerly. – Martin Mar 11 '15 at 08:39
  • I know, but to init db, you can use any kind of sql statement, and this require underlying pool created & initialized – Gokhan Oner Mar 11 '15 at 20:55