2

I have a Spring Boot App where I have configurations as in the attached image. I am getting connection error, that no connection available.

Can anyone please help in this regard? Not able to find the clue to this issue.

In my app I am not making any connection manually. Only I am injecting using @PersistenceContext annotation EntityManager or using Spring Data JPA Repository

When injecting using @PersistenceContext I am not closing EntityManager manually. Should I do that?

Update

This is the error that is coming when try to use psql to connect to the db psql: FATAL: sorry, too many clients already

SOME MORE THOUGHTS

Case 1: If i have a loop and in each loop there is a db select Or if I have a multiple threads and I have db queries in them then more connections will be opened for each query?

Case 2: But if i use @Transactional on controller endpoints then same connection will be used for all in that method stack

Are the above two statements true? Can the first case result in connections not available error?

muasif80
  • 5,586
  • 4
  • 32
  • 45
  • Add the textual error to your question. Check at OS level and DB level how many requests are in process at the moment of the error, if possible. max=10 looks a bit low depending on your application type and load. – LMC Jul 24 '19 at 23:17
  • I have updated @LuisMuñoz – muasif80 Jul 25 '19 at 13:03
  • Hey, so probably your Hikari it is consuming the max number of connections available in your PSQL database, because it creates a Pool with connections open and ready to use, and you can limit it like this: https://stackoverflow.com/questions/26490967/how-do-i-configure-hikaricp-in-my-spring-boot-app-in-my-application-properties-f – Brother Jul 25 '19 at 13:06
  • This command " SHOW max_connections;" on portgree shows the maximum number of connections allowed – Brother Jul 25 '19 at 13:08
  • Ok its 100. My question is whats wrong? pool of 50 means during app is up out of 100 50 will remain occupied? – muasif80 Jul 25 '19 at 13:23
  • So it means if i run two instances of spring app all 100 connections of postgres will be taken – muasif80 Jul 25 '19 at 13:24
  • Yes, that is the idea..each instance consumes the min-pool size +/- .. so you have to config in order to leave something for DBAs to connect using psql cmd as well. – Brother Jul 25 '19 at 13:35
  • And you shouldn't inject EntityManager and then close it manually. It is managed by spring-boot and jpa. – Brother Jul 25 '19 at 13:36

0 Answers0