How does server handle clients that disconnect ungracefully?
Hello,
I am writing an application that reads information from my PostgreSQL
database. If I cause the program to crash and the program ends without
gracefully disconnecting from the database, there is an open connection
still left in the database.
How does the PostgreSQL server handle clients that disconnect
ungracefully? Will the server automatically clean up this connection
that really is not there?
Thanks.
-Jeff
On Tue, Apr 24, 2007 at 05:53:02AM -0700, Jeff Lanzarotta wrote:
Hello,
I am writing an application that reads information from my PostgreSQL
database. If I cause the program to crash and the program ends without
gracefully disconnecting from the database, there is an open connection
still left in the database.How does the PostgreSQL server handle clients that disconnect
ungracefully? Will the server automatically clean up this connection
that really is not there?
Yes, but it will log a notice about it in the server log.
//Magnus
Jeff Lanzarotta wrote:
Hello,
I am writing an application that reads information from my PostgreSQL
database. If I cause the program to crash and the program ends without
gracefully disconnecting from the database, there is an open connection
still left in the database.How does the PostgreSQL server handle clients that disconnect
ungracefully? Will the server automatically clean up this connection
that really is not there?
Worst case is that the tcp/ip connection is never cleared down. That
means the connection will sit there until your tcp/ip stack clears it
down. I *think* that's an hour on linux.
--
Richard Huxton
Archonet Ltd
OK, thanks. I figured the server would at some point in time clear the
connection up, my question now is when does that happen? Any idea how
long the connection sit around before the server cleans it up? Someone
else said possibly an hour...
--- Magnus Hagander <magnus@hagander.net> wrote:
Show quoted text
On Tue, Apr 24, 2007 at 05:53:02AM -0700, Jeff Lanzarotta wrote:
Hello,
I am writing an application that reads information from my
PostgreSQL
database. If I cause the program to crash and the program ends
without
gracefully disconnecting from the database, there is an open
connection
still left in the database.
How does the PostgreSQL server handle clients that disconnect
ungracefully? Will the server automatically clean up thisconnection
that really is not there?
Yes, but it will log a notice about it in the server log.
//Magnus
---------------------------(end of
broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that
your
message can get through to the mailing list cleanly
On Tue, Apr 24, 2007 at 06:55:12AM -0700, Jeff Lanzarotta wrote:
OK, thanks. I figured the server would at some point in time clear the
connection up, my question now is when does that happen? Any idea how
long the connection sit around before the server cleans it up? Someone
else said possibly an hour...
Depends on yuor OS - when the TCP connection times out, PostgreSQL will
clean up and terminate the backup.
//Magnus
OK, that is what the other fellow said... It depends on the TCP/IP
stack...
Thanks again for the clarification.
--- Magnus Hagander <magnus@hagander.net> wrote:
Show quoted text
On Tue, Apr 24, 2007 at 06:55:12AM -0700, Jeff Lanzarotta wrote:
OK, thanks. I figured the server would at some point in time clear
the
connection up, my question now is when does that happen? Any idea
how
long the connection sit around before the server cleans it up?
Someone
else said possibly an hour...
Depends on yuor OS - when the TCP connection times out, PostgreSQL
will
clean up and terminate the backup.//Magnus
---------------------------(end of
broadcast)---------------------------
TIP 6: explain analyze is your friend
On Tue, Apr 24, 2007 at 07:16:38AM -0700, Jeff Lanzarotta wrote:
OK, that is what the other fellow said... It depends on the TCP/IP
stack...Thanks again for the clarification.
Note, there are two cases. If only the program crashes but the system
is fine, the kernel will close the socket for you straight away and the
server with notice the hangup.
The only time the server will wait for a time out is if the server and
the client are on different machines and something disrupts actual
communications. If the client machine crashes without notifying the
server, or someone pulls out a network cable. If the client and the
server are on the same machine, it will always notice.
Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
Show quoted text
From each according to his ability. To each according to his ability to litigate.
Martijn van Oosterhout <kleptog@svana.org> writes:
The only time the server will wait for a time out is if the server and
the client are on different machines and something disrupts actual
communications.
Right, you need connectivity loss to create an issue --- a client
program crash doesn't cause this type of problem. The most common
form of the problem that I've heard about is routers deciding to drop a
connection that's been idle too long.
BTW, on some platforms it's possible to change the timeout settings so
that a lost connection is abandoned more quickly by the TCP stack.
See the tcp_keepalives_xxx parameters if you need to do that.
regards, tom lane