Re: Is IDLE session really idle?

From: Tino Schwarze <postgresql(at)tisc(dot)de>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: Is IDLE session really idle?
Date: 2009-06-15 20:33:08
Message-ID: 20090615203308.GB20350@easy2.in-chemnitz.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hi Igor,

On Mon, Jun 15, 2009 at 01:15:30PM -0700, Igor Polishchuk wrote:

> 2. We can kill the idle sessions periodically. This will free up a big chunk
> of memory already allocated to the sessions. The application will gradually
> reestablish the connections, and the new sessions will start with small
> memory foot-print.

Don't do that. There is a race condition - if the application just
starts using the connection a millisecond after you thought it was idle
and issued the kill command, bad things might happen, depending on the
robustness of the application. It might have already validated the
connection and started the first query.

> The question is, how safe it is to kill an idle session? If a session just
> became idle in pg_stats_activity, is it possible that it is still returning
> data to the client, or doing some other useful work?

I recently figured out (on PostgreSQL 8.2.x) that an IDLE session might
still be returning query results. I wrote an application to dump whole
tables to flat files. It does a SELECT * FROM table, then streams to the
file. Access is via JDBC, results are retrieved row by row via
ResultSet.next(). I noticed that in pg_stat_activity a session switched
between IDLE and "SELECT * FROM table" command while data was being
retrieved.

HTH,

Tino.

--
"What we nourish flourishes." - "Was wir nähren erblüht."

www.lichtkreis-chemnitz.de
www.craniosacralzentrum.de

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Michael Monnerie 2009-06-15 20:35:54 Re: Is IDLE session really idle?
Previous Message Tom Lane 2009-06-15 20:32:04 Re: Is IDLE session really idle?