Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 6511A192E3B7 for ; Fri, 10 Aug 2012 03:56:38 -0300 (ADT) Received: from blu0-omc1-s22.blu0.hotmail.com ([65.55.116.33]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Szj97-0003l5-K0 for pgsql-admin@postgresql.org; Fri, 10 Aug 2012 06:56:37 +0000 Received: from BLU0-SMTP394 ([65.55.116.7]) by blu0-omc1-s22.blu0.hotmail.com with Microsoft SMTPSVC(6.0.3790.4675); Thu, 9 Aug 2012 23:56:18 -0700 X-Originating-IP: [61.170.253.133] X-EIP: [m8OpvpITQlBnfc3fIwh9aG/j+SUXuBRT] X-Originating-Email: [liuhaifeng@live.com] Message-ID: Received: from [172.16.224.42] ([61.170.253.133]) by BLU0-SMTP394.blu0.hotmail.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.4675); Thu, 9 Aug 2012 23:56:17 -0700 From: Haifeng Liu Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: JDBC keep alive issue Date: Fri, 10 Aug 2012 14:56:02 +0800 To: "pgsql-admin@postgresql.org" MIME-Version: 1.0 (Mac OS X Mail 6.0 \(1485\)) X-Mailer: Apple Mail (2.1485) X-OriginalArrivalTime: 10 Aug 2012 06:56:17.0886 (UTC) FILETIME=[3DAAEFE0:01CD76C5] X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/76 X-Sequence-Number: 39897 Hi experts, I have a program running like a daemon, which analyze data and write to pos= tgresql 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 t= he 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=3Dtrue; postgresql:9.1, keep alive related settings use default values(commented); centos 5.8 64bit, net.ipv4.tcp_keepalive_intvl =3D 75, probes =3D 9, time = =3D 7200. There is no firewall or any other device which behaves force idle connectio= n 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 ) 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 ) 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 To: Haifeng Liu cc: "pgsql-admin@postgresql.org" Subject: Re: JDBC keep alive issue In-reply-to: References: Comments: In-reply-to Haifeng Liu 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 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