Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot 2 with pgBouncer pooling

I have a PostgreSQL 11 server with pgBouncer pooling set up and enabled.

I'd like to use its pooling mechanism rather than default Hikari and Tomcat pooling that come with the Spring Boot's spring-boot-starter-data-jpa. I've disabled HikariCP and tomcat-jdbc from the project however, I'm not sure what I'd need to set up further in order to launch the Spring app successfully.

I guess my question is how to set up a Spring application so that it doesn't use any pooling mechanism to communicate with the db as it will be handled by pgBouncer on the db side?

I have looked at a variety of questions and answers to somewhat similar questions which led to me disabling HikariCP to start with. However, I was unable to find a concise tutorial/example of how I could make this work in my case scenario.

Any help would be really appreciated.

like image 682
curiousdev Avatar asked Mar 02 '23 15:03

curiousdev


1 Answers

I had similar problem, and after looking at the spring source codes I found an easier way that does not require any code or pom changes.

spring:
  datasource:
    type: org.springframework.jdbc.datasource.DriverManagerDataSource
    driver-class-name: org.postgresql.Driver

This datasource will simply replace hikari and create a new connection every time instead of pooling.

like image 178
HenryCo Avatar answered Mar 05 '23 16:03

HenryCo