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 1hGP7T-0005dz-Jz for pgsql-general@arkaria.postgresql.org; Tue, 16 Apr 2019 14:31:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hGP7S-00046Y-3U for pgsql-general@arkaria.postgresql.org; Tue, 16 Apr 2019 14:31:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGP7R-00045q-N4 for pgsql-general@lists.postgresql.org; Tue, 16 Apr 2019 14:31:29 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hGP7L-0006EF-FB for pgsql-general@lists.postgresql.org; Tue, 16 Apr 2019 14:31:28 +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 x3GEVEoE026882; Tue, 16 Apr 2019 10:31:14 -0400 From: Tom Lane To: "Takahashi, Ryohei" cc: "pgsql-general@lists.postgresql.org" , "'Andreas Kretschmer'" , "'Francisco Olarte'" Subject: Re: SQLSTATE when PostgreSQL crashes during COMMIT statement In-reply-to: References: <0edda023-5788-7971-50de-d5fca6208b6c@a-kretschmer.de> Comments: In-reply-to "Takahashi, Ryohei" message dated "Tue, 16 Apr 2019 04:44:54 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26880.1555425074.1@sss.pgh.pa.us> Date: Tue, 16 Apr 2019 10:31:14 -0400 Message-ID: <26881.1555425074@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "Takahashi, Ryohei" writes: >> So, if the library gives you an error ( "I have not received the commit >> confirmation" , not something like "commit failed" ), you will still >> need to test the data, if you can, to know how the server come back up. > Yes. > I want to know what error does library give to the application on such case. > I supposed it is certain SQLSTATE. libpq, at least, doesn't produce SQLSTATEs for errors that it detects. (It probably should, but that's been a TODO item for a couple of decades now ... so don't hold your breath.) So the best you can do here is to check the error message spelling. A crude but possibly sufficient approach is to assume that once you've got a working connection, *any* error that lacks a SQLSTATE is indicative of connection loss. This idea could fail for cases like out-of-memory, but if your app is at the edge of OOM then giving up might be wise anyway. regards, tom lane