Re: Getting the SQLSTATE after a failed connection

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Getting the SQLSTATE after a failed connection
Date: 2025-10-17 16:53:45
Message-ID: 1710946.1760720025@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com> writes:
> On Fri, 17 Oct 2025 at 16:49, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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

In response to

Browse pgsql-hackers by date

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