1

I have one spring boot application and am using managed postgres as backend. I do not have any admin permissions on postgres.

If i do not mention anything in my spring boot application, does that mean is it using some connection pooling?

my spring boot application.yml is like below

spring:
  profiles: prod
  datasource:
    driver-class-name: org.postgresql.Driver
    url: <<jdbc-url>>
    username: prddb
    password:
    tomcat:
      validation-interval: 30000
      test-on-borrow: true
      validation-query: SELECT 1

when check i dashboard, my apps almost using all connections .

James Z
  • 12,209
  • 10
  • 24
  • 44
Bravo
  • 8,589
  • 14
  • 48
  • 85
  • It depends on your jars, can you show your pom.xml? do you have tomcat-jdbc? – Ori Marko Jan 21 '19 at 10:31
  • @user7294900 , mine is gradle project i saw my downloaded dependencies tomcat-jdbc:8.5.34 , does that mean , connection pool already present and configured ? – Bravo Jan 21 '19 at 10:33
  • Just saw spring boot internally has tomcat-jdbc , which has connection pooling , but may i know what are the default configurations for this connection pool ? how to change the max idle connections in our spring boot , i mean can we override this settings ? – Bravo Jan 21 '19 at 10:59
  • See in logs, are you loading tomcat or hikari connection pool? for tomcat set under `tomcat` `max-active: 50` – Ori Marko Jan 21 '19 at 11:00
  • thanks , i just saw it is tomcat jdbc connection pool org.apache.tomcat.jdbc.pool.DataSource@XXXXX – Bravo Jan 21 '19 at 11:17
  • i have one more doubt , if same data base details , if i use in another 2 seperate applications , in total three connections pools are present for this data , am i connect ? when i saw the default connection pool details maxActive=100; maxIdle=100; minIdle=10; initialSize=10; maxWait=30000; – Bravo Jan 21 '19 at 11:21
  • do i need override maxActive to 50 ? – Bravo Jan 21 '19 at 11:22

1 Answers1

1

If you added the dependency in pom.xml, spring boot should scan and create a connection pool, else you can specify the datasource manually in the .properties file like so:

spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource

Also to test the connection Pool, you can create a simple test:

@RunWith(SpringRunner.class)
@SpringBootTest
public class ConnectionPoolTest {

@Autowired
private DataSource dataSource;

@Test
public void connectionPoolTest() {
    assertThat(dataSource.getClass().getName())
      .isEqualTo("org.apache.tomcat.jdbc.pool.DataSource");
 }
}
Manuel PR
  • 11
  • 1
  • 4