DB Connections in TIME_WAIT state

From: John Gateley <gateley(at)jriver(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: DB Connections in TIME_WAIT state
Date: 2008-05-13 13:22:15
Message-ID: 20080513082215.52b18cd3.gateley@jriver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi, I'm using the Pg perl module to connect to Postgresql 8.1
via localhost (127.0.0.1) from webscripts. I'm noticing a lot
of TIME_WAIT socket connections:

tcp 0 0 127.0.0.1:39291 127.0.0.1:5432 TIME_WAIT
tcp 0 0 127.0.0.1:60720 127.0.0.1:5432 TIME_WAIT
tcp 0 0 127.0.0.1:60735 127.0.0.1:5432 TIME_WAIT
tcp 0 0 127.0.0.1:60769 127.0.0.1:5432 TIME_WAIT
tcp 0 0 127.0.0.1:39281 127.0.0.1:5432 TIME_WAIT
...

I think the number is high enough (200~250) that sometime the
server runs out of sockets.

What's the proper way to close the postgresql connection so that
it doesn't go into a TIME_WAIT state?

I tried:

use Pg;
my $Connection = Pg::connectdb($ConnectString);
... do some stuff
$Connection = 0;

That doesn't seem to close the connection.

Any ideas?

Thanks,

j
--
John Gateley <gateley(at)jriver(dot)com>

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stefan Schwarzer 2008-05-13 13:26:57 Substring Problem
Previous Message Glyn Astill 2008-05-13 13:02:54 Re: Stripping out slony after / before / during pg_restore?