Applications that leak connections - Mailing list pgsql-general

From Paul Tillotson
Subject Applications that leak connections
Date
Msg-id 4202B372.6000808@shentel.net
Whole thread Raw
Responses Re: Applications that leak connections  ("Jonel Rienton" <jonel@road14.com>)
Re: Applications that leak connections  (Neil Conway <neilc@samurai.com>)
List pgsql-general
Does anyone have any useful info about dealing with applications which
"leak" connections, eventually causing "connection limit exceeded for
non superusers?"

Obviously fixing the app is the best choice, but I have a feeling that
this is going to recur again and again since the app is poorly
maintained but still under active development (code base too large for
the developer assigned to it).  The developer is likely to accidentally
cause connection leaks in the future.

This problem is also very easy to cause because doing this:

c = sqlconnect("database")
c = sqlconnect("database")

Causes TWO connections to be made, and the first connection made is now
(as far as I can see) impossible to close without closing the
application.  The language (Visual Foxpro) does not garbage collect
connections and so any connection whose handle is lost still takes up
one of the slots.

On the server side, I can detect this condition using ps -A or lsof; but
I have not thought of a good solution to use when this is noticed.  One
possibility is to just shut down the database and restart it when this
happens.  I did some research into finding out if it was possible to
break a specific TCP connection (this is linux 2.6 kernel--platform
specific tools/commands ok).  For example, could I use hping to break
the connections?

Does anyone know a safe way to shutdown just one backend (if it is idle)?

Another possibility that I can think of is per ip address connection
limits.  How hard would that be?

Paul Tillotson



pgsql-general by date:

Previous
From: Philippe Schmid
Date:
Subject: Start problem on OSX
Next
From: Joseph Kiniry
Date:
Subject: Backing up and restoring a database with the SELinux pg_user problem.