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