IDLE queries taking up space

Started by JD Wongover 14 years ago5 messagesgeneral
Jump to latest
#1JD Wong
jdmswong@gmail.com

Hi,

When I run select datname, procpid, current_query from pg_stat_activity; I
get 26 rows of <IDLE> queries. How can I set postgres to qutomatically
close connections that have finished their queries and now sit idle?

Thanks!
-JD

#2Scott Ribe
scott_ribe@elevated-dev.com
In reply to: JD Wong (#1)
Re: IDLE queries taking up space

On Aug 30, 2011, at 10:03 AM, JD Wong wrote:

How can I set postgres to qutomatically close connections that have finished their queries and now sit idle?

They haven't finished their queries. They've opened transactions, and then are sitting there doing nothing. In other words, this is a bug in your clients, and no, you really would not want PG automatically terminating connections mid-transaction just because it thought the client was taking too long to get to the next step.

--
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
(303) 722-0567 voice

#3Rodrigo Gonzalez
rjgonzale@estrads.com.ar
In reply to: Scott Ribe (#2)
Re: IDLE queries taking up space

On 08/30/2011 02:13 PM, Scott Ribe wrote:

On Aug 30, 2011, at 10:03 AM, JD Wong wrote:

How can I set postgres to qutomatically close connections that have finished their queries and now sit idle?

AFAIK you can't, you should check |pg_terminate_backend function and see
if it is useful for you
|

They haven't finished their queries. They've opened transactions, and then are sitting there doing nothing. In other words, this is a bug in your clients, and no, you really would not want PG automatically terminating connections mid-transaction just because it thought the client was taking too long to get to the next step.

<IDLE> in transaction is what you mean...
<IDLE> are clients connected but not running any query

Show quoted text
#4Merlin Moncure
mmoncure@gmail.com
In reply to: JD Wong (#1)
Re: IDLE queries taking up space

On Tue, Aug 30, 2011 at 11:03 AM, JD Wong <jdmswong@gmail.com> wrote:

Hi,
When I run select datname, procpid, current_query from pg_stat_activity; I
get 26 rows of <IDLE> queries.  How can I set postgres to qutomatically
close connections that have finished their queries and now sit idle?

you don't. this should be managed from the client, or you can use a
connection pool.

merlin

#5Craig Ringer
craig@2ndquadrant.com
In reply to: JD Wong (#1)
Re: IDLE queries taking up space

On 31/08/2011 12:03 AM, JD Wong wrote:

Hi,

When I run select datname, procpid, current_query from
pg_stat_activity; I get 26 rows of <IDLE> queries. How can I set
postgres to qutomatically close connections that have finished their
queries and now sit idle?

If they're not idle in transaction, they don't matter much.

Try filtering the list based on last activity, so you only see those
connections that have been idle for a while. Short periods of idle are
normal for many applications because they perform a query then process
its results and issue other queries based on the results, or because
they keep a connection around between requests from users.

If the idle connections are actually causing an issue - for example, if
they're preventing the release of non-trivial amounts of backend private
memory back to the OS - you can tweak the client to disconnect after a
certain idle time, or you can use a connection pool. Connection pools
may be inside the client (for example, in Java EE application servers)
or between the client and the server using tools like pgbouncer and
PgPool-II.

--
Craig Ringer