Re: Getting the SQLSTATE after a failed connection - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Getting the SQLSTATE after a failed connection
Date
Msg-id 1710946.1760720025@sss.pgh.pa.us
Whole thread Raw
In response to Re: Getting the SQLSTATE after a failed connection  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
List pgsql-hackers
Daniele Varrazzo <daniele.varrazzo@gmail.com> writes:
> On Fri, 17 Oct 2025 at 16:49, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> I'd be in favor of adding some API here as long as it's not
>> myopic about the complexity of the problem.

> If the complexity comes from having to store a sqlstate for every
> attempt, I'd like to point out that the multiple attempts algorithms
> only kick in for sync connections; at the moment any client wanting to
> connect asynchronously needs to replicate dns results expansion,
> multiple hosts/ports handling, timeout implementation, pg_serivce
> management, target_session_attr, load_balance_hosts=random, etc.

I'm not sure that that's true, and even if it is, I don't think it's
relevant.  The way we've extended the behavior of PQconnect* over
the last dozen or so years means that "there was only one connection
attempt" is not an assumption an application can safely make.
I don't want to add APIs that depend on that assumption to be useful.

> If the content of `PGconn.last_sqlstate` is well maintained,

That's a large "if", too.  We never intended it to be exposed;
it was only meant to be consulted shortly after the fact within
libpq itself.  I don't think much thought has been given to
questions like exactly when to reset it.

            regards, tom lane



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Inconsistent Behavior of GROUP BY ROLLUP in v17 vs master
Next
From: Nathan Bossart
Date:
Subject: abi-compliance-check failure due to recent changes to pg_{clear,restore}_{attribute,relation}_stats()