Re: Handling idle connections - Mailing list pgsql-admin

From Erik Wienhold
Subject Re: Handling idle connections
Date
Msg-id kd2wgxkkdydj55fmu5hrewi2xtdb47t3l4kzv7xryd2b7rpxmk@zdqaigztd5pa
Whole thread Raw
In response to Handling idle connections  (Rajesh Kumar <rajeshkumar.dba09@gmail.com>)
List pgsql-admin
On 2023-09-24 12:57 +0530, Rajesh Kumar wrote:
> What is the best way to handle idle connections other than manually killing
> idle connections if I do not have connection pooler.

Couple of options depending on your Postgres version and whether you
only care about idle connections with open transactions:

* set idle_in_transaction_session_timeout [1] for idle connections with
  an open transaction

* set idle_session_timeout [2] (requires pg14+) for idle connections
  without an open transaction

* use a cron job that checks connections in view pg_stat_activity and
  terminates them as necessary

[1]
https://www.cybertec-postgresql.com/en/idle_in_transaction_session_timeout-terminating-idle-transactions-in-postgresql/
[2] https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-IDLE-SESSION-TIMEOUT

-- 
Erik



pgsql-admin by date:

Previous
From: Scott Ribe
Date:
Subject: Re: Handling idle connections
Next
From: Zhaoxun Yan
Date:
Subject: Re: Corruption issue