JDBC keep alive issue

From: Haifeng Liu <liuhaifeng(at)live(dot)com>
To: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: JDBC keep alive issue
Date: 2012-08-10 06:56:02
Message-ID: BLU0-SMTP394B69FD9FE644CD7BA022DB9B30@phx.gbl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

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(at)postgresql(dot)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(at)sss(dot)pgh(dot)pa(dot)us>)
id 1SzxbP-0005QF-8o
for pgsql-admin(at)postgresql(dot)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(at)sss(dot)pgh(dot)pa(dot)us>)
id 1Szq3u-0006pL-I3
for pgsql-admin(at)postgresql(dot)org; Fri, 10 Aug 2012 14:19:39 +0000
Received: from sss2.sss.pgh.pa.us (tgl(at)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(at)sss(dot)pgh(dot)pa(dot)us>
To: Haifeng Liu <liuhaifeng(at)live(dot)com>
cc: "pgsql-admin(at)postgresql(dot)org" <pgsql-admin(at)postgresql(dot)org>
Subject: Re: JDBC keep alive issue
In-reply-to: <BLU0-SMTP394B69FD9FE644CD7BA022DB9B30(at)phx(dot)gbl>
References: <BLU0-SMTP394B69FD9FE644CD7BA022DB9B30(at)phx(dot)gbl>
Comments: In-reply-to Haifeng Liu <liuhaifeng(at)live(dot)com>
message dated "Fri, 10 Aug 2012 14:56:02 +0800"
Date: Fri, 10 Aug 2012 10:19:24 -0400
Message-ID: <23654(dot)1344608364(at)sss(dot)pgh(dot)pa(dot)us>
X-Pg-Spam-Score: -1.9 (-)
X-Archive-Number: 201208/77
X-Sequence-Number: 39898

Haifeng Liu <liuhaifeng(at)live(dot)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

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Craig James 2012-08-11 11:26:06 Re: JDBC keep alive issue
Previous Message Craig Ringer 2012-08-10 05:19:56 Re: Data migration to sql server 2008