Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGlrX-0003hj-3U for pgsql-general@arkaria.postgresql.org; Wed, 17 Apr 2019 14:48:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hGlrU-0005Up-5F for pgsql-general@arkaria.postgresql.org; Wed, 17 Apr 2019 14:48:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGlrT-0005Ui-SP for pgsql-general@lists.postgresql.org; Wed, 17 Apr 2019 14:48:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGlrN-0007Bb-KU for pgsql-general@postgresql.org; Wed, 17 Apr 2019 14:48:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x3HEmJPT030389; Wed, 17 Apr 2019 10:48:19 -0400 From: Tom Lane To: Adrian Klaver cc: Ajay Pratap , pgsql-general@postgresql.org Subject: Re: PostgreSQL ping/pong to client In-reply-to: <70c44319-1ff8-8d26-ceba-db2b20d8496d@aklaver.com> References: <70c44319-1ff8-8d26-ceba-db2b20d8496d@aklaver.com> Comments: In-reply-to Adrian Klaver message dated "Wed, 17 Apr 2019 07:29:38 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30387.1555512499.1@sss.pgh.pa.us> Date: Wed, 17 Apr 2019 10:48:19 -0400 Message-ID: <30388.1555512499@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Adrian Klaver writes: > On 4/17/19 5:39 AM, Ajay Pratap wrote: >> I am using PostgreSQL 10.7 as the database, and have Java web app. My >> app takes a lock on the database using the following command whenever my >> server is starting. >> /select /pg_try_advisory_lock/(100)/ >> To make sure only one instance of the App is using the database at a time. >> There have been several instances when my server crashes(or stops/ or >> kill), but this lock still remained on the PostgreSQL. Ideally, this >> should not happen because TCP connection breaks if one of the peers >> dies, but it happens otherwise. >> To solve this problem PostgreSQL needs to break the connection if the >> client dies. > But the problem as you describe it is that the server dies not the client. An advisory lock wouldn't survive a server reboot, so there's something not very accurate about this description. I suspect what the OP wants is quicker detection of client connection loss, and yes, messing with TCP timeouts and/or keepalive is the only way. regards, tom lane