I have some questions about how HikariCP’s maxLifetime configuration interacts with PostgreSQL’s idle_in_transaction_session_timeout.
From my understanding:
maxLifetimedetermines how long a connection can remain in the pool before being retired. If a connection that exceeds this threshold is still marked as in use, it will never be retired. By default, this value is set to 30 minutes, and it is recommended to be several seconds lower than any database timeouts. The HikariCP documentation suggests setting this parameter properly to prevent application performance degradation.idle_in_transaction_session_timeoutdefines how long a session can remain idle while waiting for a client query within an open transaction. Once this threshold is exceeded, the session is closed. This is particularly useful to prevent idle sessions from holding locks for too long, which could degrade database performance. By default, RDS sets this parameter to 24 hours—a very long time, in my opinion.
With this in mind, here are my questions:
- If I change only one of these parameters, will it affect the other? For example, if I keep both at their default values, what happens if a connection exceeds the maxLifetime configured in HikariCP but remains idle in a transaction session?
- How can I find an optimal configuration for these parameters to prevent performance degradation on both the application and database sides? If I understand correctly, for
idle_in_transaction_session_timeout, I should monitor transaction durations and fine-tune the value while ensuring sessions are not being closed too frequently. FormaxLifetime, the documentation recommends setting it a few seconds lower thanidle_in_transaction_session_timeout, but I’m unsure if further tuning is needed or if other PostgreSQL parameters impact this behavior.
Right now i have already set the idle_in_transaction_session_timeout from the 24 hours defaulted by RDS to 31 minutes, but i what to ensure that what i'm doing has a measurable impact.
Thanks in advance for any insights and please don’t hesitate to correct me if I’ve misunderstood anything!