There are tcp_keepalives on the server side of postgresql The problem was that debian waits 2 hours before starting the keepalives (7200 s). Also, the connection would only be kept alive for 9*75 s, which is 11 min.
So i changed the tcp_keepalives_idle to 120 (keepalives start after 2 min) and the tcp_keepalives_count to 200 (max 200 keepalives are sent, every 75 secs, so the connection is kept alive for 120+(200*75) secs, which is 4.2 hours. It seems to have worked. I'll check if it works on Windows. ==in postgresql.conf== # - TCP Keepalives - # see "man 7 tcp" for details #tcp_keepalives_idle = 0 # TCP_KEEPIDLE, in seconds; # 0 selects the system default #tcp_keepalives_interval = 0 # TCP_KEEPINTVL, in seconds; # 0 selects the system default #tcp_keepalives_count = 0 # TCP_KEEPCNT; # 0 selects the system default ==in man 7 tcp (debian lenny)== tcp_keepalive_intvl (integer; default: 75) The number of seconds between TCP keep-alive probes. tcp_keepalive_probes (integer; default: 9) The maximum number of TCP keep-alive probes to send before giving up and killing the connection if no response is obtained from the other end. tcp_keepalive_time (integer; default: 7200) The number of seconds a connection needs to be idle before TCP begins sending out keep-alive probes. Keep-alives are only sent when the SO_KEEPALIVE socket option is enabled. The default value is 7200 seconds (2 hours). An idle connection is terminated after approximately an additional 11 minutes (9 probes an interval of 75 seconds apart) when keep-alive is enabled. Note that underlying connection tracking mechanisms and application timeouts may be much shorter. Cheers, WBL