Re: Handling idle connections

From: Rui DeSousa <rui(at)crazybean(dot)net>
To: Rajesh Kumar <rajeshkumar(dot)dba09(at)gmail(dot)com>
Cc: Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: Handling idle connections
Date: 2023-09-24 18:15:28
Message-ID: AB0BD6D8-DFE1-4918-9AF6-0A9A1ED5CEBE@crazybean.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

> On Sep 24, 2023, at 3:27 AM, Rajesh Kumar <rajeshkumar(dot)dba09(at)gmail(dot)com> wrote:
>
> Hi
>
> What is the best way to handle idle connections other than manually killing idle connections if I do not have connection pooler.

Are they actually a problem? Depending on your application, it may be doing connection pooling (most do) and/or killing the sessions could create problems for the application.

Here’s what I normally do.

1. Setup idle_in_transaction_session_timeout — these are idle sessions with open transactions. This is most likely a bug in the application or a very bad practice. Applications shouldn’t be leaving open transaction idle for long periods of time — at most a few minutes. I seen environments where the thought was hour long idle in sessions transactions was considered normal; it’s not. We had to create tickets to manually kill them after an hour or when they started to create issues. The development team was non responsive in fixing these issues and the DBA team didn’t have any authority to mandate it.

2. Setup TCP/IP timeouts to flush out abandoned idle sessions (i.e. server crashes, people unplugging the network cable without logging out, firewall dropping the connection without sending reset packets, etc).

3. Setup up a cron job to kill long idle sessions from non applications accounts/networks.

Killing idle sessions just because they are idle could cause problems for the application. I seen one application a that would detect multiple bad connections and then do a hard reboot. Killing idle sessions would cause the entire application to go down and reset itself resulting in the site not being available for couple of minutes. Point is, know your application and why it currently has idle sessions before killing them indiscriminately.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Rajesh Kumar 2023-09-24 22:07:25 Re: Handling idle connections
Previous Message David G. Johnston 2023-09-24 15:05:41 Re: Handling idle connections