I have a Spring Boot application (v2.2.5.RELEASE) that uses JPA (Hibernate) to connect to a Postgres DB. Spring Boot uses HikariCP for connection pooling. In my production environment, I see the following query executed every few seconds regardless of DB activity (almost as if they are some kind of health check?):
SET application_name = 'PostgreSQL JDBC Driver'
ps: the CPU Utilisation % goes above 350% after 3 hours of starting application in server
Are these queries necessary? Can they be avoided?
configuration of HikariCP in application.properties
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
# Hikari will use the above plus the following to setup connection pooling
spring.datasource.hikari.minimumIdle=5
spring.datasource.hikari.maximumPoolSize=10
spring.datasource.hikari.idleTimeout=300
spring.datasource.hikari.poolName=SpringBootJPAHikariCP
spring.datasource.tomcat.maxIdle=150
spring.jpa.hibernate.connection.provider_class=org.hibernate.hikaricp.internal.HikariCPConnectionProvider
spring.datasource.hikari.connectionTimeout=30000
spring.datasource.hikari.maxLifetime=30000
spring.datasource.testWhileIdle=true
spring.datasource.validationQuery=SELECT 1
This SQL statement is run whenever the JDBC driver establishes a connection to PostgreSQL. If you see that statement very often, that means that you open (and hopefully close) lots of database connections, that is, you open a database connection for each request.
Opening database connections is very expensive. If my guess is right, you should use a connection pool and persistent, long-lived database connections. That will reduce the load and improve throughput.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With