Spring Boot application performs extremely high number of SET application_name queries to postgres
Asked Answered
N

1

7

I have a Spring Boot application (v2.1.5) 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'

I am struggling to get to the bottom of why these queries are performed so often and if they can be avoided because in my local environment the above statement is only executed when a query to the DB is performed. I still do not understand why, but it is less frequent and different behaviour compared to production.

Are these queries necessary? Can they be avoided? Thanks.

UPDATE:

Here is a screenshot of the queries received by the DB to which the Spring boot app is connecting using HikariCP. The time is shown as "Just now" because all of the query shown are only ~0.5 seconds apart and all within the "current minute".

enter image description here

Necktie answered 2/11, 2020 at 18:9 Comment(0)
S
3

This seems to be performed by the Hikari Connection Pool. See Default HikariCP connection pool starting Spring Boot application and it's answers.

I wouldn't bother about it since, it is not performing a "extremely high number" of these operations, but only every few seconds, possibly whenever a connection is handed out by or returned to the pool.

If it really bothers you, you could look into various places for disabling it.

The last comment here suggests that setting the connection property assumeMinServerVersion to 9.0 or higher might help.

Since this is probably triggered by the HikariConnectionPool it might be configurable there, by configuring the behaviour when starting, lending and returning a connection.

Showpiece answered 3/11, 2020 at 11:2 Comment(3)
Thanks for the answer. I did suspect it was HikariCP. TBH I am not experiencing poor performance from the DB, but the numbers (I have updated my answer with a screenshot) are a bit disconcerting...I will try the suggested approach from the postgresql archive post and report back.Necktie
I have set the assumeMinServerVersion on my DB URL to 10.0 but I still see 2 or 3 transactions per second happening, on the HikariCP connectionsNecktie
Hi, Did you find any solution ; in my case all of those connections are shown as idle in postgres with these queries and the no is around 200 .Rondi

© 2022 - 2024 — McMap. All rights reserved.