Subject: [Dev] PostgreSQL connection timeout

From: "Richard O. Hammer" <[email-masked]>
Date: Tue, 13 Jan 2004 18:10:22 -0500

I have PostgreSQL 7.3.2 running on Red Hat 7.3, and I am connecting to 
it from a Java Virtual Machine on Windows 2000.  Usually it runs fine. 
   But sometimes it breaks, seemingly with a connection timeout.  I 
hope for suggestions on what to do about this.

When my problem happens, I get a stack trace like this on the client 
(Windows) side:

An I/O error occurred while reading from backend - Exception: 
java.net.SocketException: Connection reset by peer: JVM_recv in socket 
input stream read
Stack Trace:

java.net.SocketException: Connection reset by peer: JVM_recv in socket 
input stream read
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.read(SocketInputStream.java:116)
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:183)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:201)
	at org.postgresql.PG_Stream.ReceiveChar(PG_Stream.java:138)
	at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:71)
...

And on the Linux server side I see the following message in
/var/log/messages.  I believe this message relates to the problem I am 
having.

Jan 10 22:54:59 r postgres[27572]: [1] LOG:  pq_recvbuf: recv() 
failed: Connection timed out

Searching, I found my error message mentioned on one PostgreSQL email 
list.  The reply given there told that this is not a PostgreSQL 
problem, but an underlying kernel or TCP thing on Linux.

So, I don't know what to ask exactly, but is there a default TCP 
connection timeout on Linux?  that I could maybe set?

Thanks,
Rich Hammer

---

From: Jon Carnes <[email-masked]>
Date: Wed, 14 Jan 2004 03:21:04 -0000

Did you see this entry?
 http://forums.devshed.com/t45649/s.html

This guy had no problems if both machines were on the same subnet since
the connection was directly machine to machine (no firewall or router
in-between).

You might want to modify your app to put a small heart-beat across the
connection every 10 seconds. Read an update block in the Database every
10 seconds.  That will act as a keep-alive.

Good Luck - Jon Carnes

On Tue, 2004-01-13 at 18:10, Richard O. Hammer wrote:
> _______________________________________________
> Dev mailing list
> [email-masked]
> http://www.trilug.org/mailman/listinfo/dev

---

From: "Richard O. Hammer" <[email-masked]>
Date: Wed, 14 Jan 2004 09:36:29 -0500

> the connection was directly machine to machine (no firewall or router

Thank you, Jon.  I had not found that entry.  My two machines are both 
connected to local ports on a Linksys cable/DSL router (this router 
also uplinks to my DSL modem).  So I believe it would be accurate to 
say my two machines are both in the same subnet; they are 192.168.1.2 
and 192.168.1.3 .  I don't suppose that is my problem.

I've just discovered /proc/sys/net/ipv4/tcp_keepalive_time, and I'm 
saying Hmmm.

Also, I suspect one factor may be that my Windows 2000 machine goes 
into standby when I walk away from it for 25 minutes, and my 
connection-reset problems with PostgreSQL on my RH7.3 machine all 
occur during these long intervals, so far at least.  I don't know 
exactly which services continue to operate during Windows standby, but 
I wonder if TCP stops sending keepalive segments.