Re: SQLSTATE when PostgreSQL crashes during COMMIT statement - Mailing list pgsql-general

From Tom Lane
Subject Re: SQLSTATE when PostgreSQL crashes during COMMIT statement
Date
Msg-id 26881.1555425074@sss.pgh.pa.us
Whole thread Raw
In response to RE: SQLSTATE when PostgreSQL crashes during COMMIT statement  ("Takahashi, Ryohei" <r.takahashi_2@jp.fujitsu.com>)
List pgsql-general
"Takahashi, Ryohei" <r.takahashi_2@jp.fujitsu.com> 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



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Alter domain type / avoiding table rewrite
Next
From: Tom Lane
Date:
Subject: Re: Alter domain type / avoiding table rewrite