pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Haifeng Liu <liuhaifeng@live.com>
To: pgsql-admin@postgresql.org <pgsql-admin@postgresql.org>
Subject: JDBC keep alive issue
Date: Fri, 10 Aug 2012 14:56:02 +0800
Message-ID: <BLU0-SMTP394B69FD9FE644CD7BA022DB9B30@phx.gbl> (raw)

Hi experts,

I have a program running like a daemon, which analyze data and write to postgresql 9.1 on centos 5.8. There is only one connection between my program and the postgresql database, and I hope the connection may keep alive all the time. But I failed, the connection will be reset after idle for about 2 hours.

jdbc driver: 9.1-901, connection url has parameter tcpKeepAlive=true;
postgresql:9.1, keep alive related settings use default values(commented);
centos 5.8 64bit, net.ipv4.tcp_keepalive_intvl = 75, probes = 9, time = 7200.

There is no firewall or any other device which behaves force idle connection cleanup.

Am I missing some configurations? What's the right way to keep a long time connection?
From pgsql-admin-owner@postgresql.org  Fri Aug 10 22:22:52 2012
Received: from makus.postgresql.org ([98.129.198.125])
	by malur.postgresql.org with esmtp (Exim 4.72)
	(envelope-from <tgl@sss.pgh.pa.us>)
	id 1SzxbP-0005QF-8o
	for pgsql-admin@postgresql.org; Fri, 10 Aug 2012 22:22:43 +0000
Received: from sss.pgh.pa.us ([66.207.139.130])
	by makus.postgresql.org with esmtp (Exim 4.72)
	(envelope-from <tgl@sss.pgh.pa.us>)
	id 1Szq3u-0006pL-I3
	for pgsql-admin@postgresql.org; Fri, 10 Aug 2012 14:19:39 +0000
Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1])
	by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q7AEJO7F023655;
	Fri, 10 Aug 2012 10:19:24 -0400 (EDT)
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Haifeng Liu <liuhaifeng@live.com>
cc: "pgsql-admin@postgresql.org" <pgsql-admin@postgresql.org>
Subject: Re: JDBC keep alive issue
In-reply-to: <BLU0-SMTP394B69FD9FE644CD7BA022DB9B30@phx.gbl>
References: <BLU0-SMTP394B69FD9FE644CD7BA022DB9B30@phx.gbl>
Comments: In-reply-to Haifeng Liu <liuhaifeng@live.com>
	message dated "Fri, 10 Aug 2012 14:56:02 +0800"
Date: Fri, 10 Aug 2012 10:19:24 -0400
Message-ID: <23654.1344608364@sss.pgh.pa.us>
X-Pg-Spam-Score: -1.9 (-)
X-Archive-Number: 201208/77
X-Sequence-Number: 39898

Haifeng Liu <liuhaifeng@live.com> writes:
> I have a program running like a daemon, which analyze data and write to postgresql 9.1 on centos 5.8. There is only one connection between my program and the postgresql database, and I hope the connection may keep alive all the time. But I failed, the connection will be reset after idle for about 2 hours.

> jdbc driver: 9.1-901, connection url has parameter tcpKeepAlive=true;
> postgresql:9.1, keep alive related settings use default values(commented);
> centos 5.8 64bit, net.ipv4.tcp_keepalive_intvl = 75, probes = 9, time = 7200.

IIRC, time = 7200 (seconds) means to start sending keepalive packets
after 2 hours of idle time.  So if you have something in the way that is
dropping the connection after 2 hours, these settings will not activate
keepalive soon enough to save it.  I'd try setting that to 3600.

> There is no firewall or any other device which behaves force idle connection cleanup.

Seems pretty darn unlikely given these symptoms.  Look harder...
maybe something you thought was just a bridge has got routing behavior.

BTW, in the real world connections drop for all sorts of reasons, and
kernel keepalive configurations can't prevent them all.  You might be
better advised to build some reconnect-after-connection-loss logic into
your application, rather than spending time on making this work.

			regards, tom lane




view thread (2+ messages)  latest in thread

Message-ID: <BLU0-SMTP394B69FD9FE644CD7BA022DB9B30@phx.gbl>
Permalink:  ../BLU0-SMTP394B69FD9FE644CD7BA022DB9B30@phx.gbl/
Also on:    postgresql.org/message-id/BLU0-SMTP394B69FD9FE644CD7BA022DB9B30@phx.gbl

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: liuhaifeng@live.com
  Subject: Re: JDBC keep alive issue
  In-Reply-To: <BLU0-SMTP394B69FD9FE644CD7BA022DB9B30@phx.gbl>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox