Re: BUG #16508: using multi-host connection string when the first host is starting fails

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: jv(dot)cyril(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16508: using multi-host connection string when the first host is starting fails
Date: 2020-08-13 22:08:14
Message-ID: 530083.1597356494@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Noah Misch <noah(at)leadboat(dot)com> writes:
> On Wed, Jun 24, 2020 at 08:17:44AM +0000, PG Bug reporting form wrote:
>> I'm connection to pg10 using psql (tried with clients psql 10.11 & psql
>> 12.2) using a connection string such as:
>> psql 'dbname=xxxxx1,xxxxx2,xxxxx3,xxxxx4 target_session_attrs=read-write'
>>
>> the connection to first database (xxxxx1) fail with the error:
>> psql.bin: FATAL: the database system is starting up
>>
>> which is correct according to postgres state on that machine,
>> but then I would expect the psql tries the next server (xxxxx2) with is in
>> the one acceptiong the connection params (target_session_attrs=read-write)
>> instead of the error.

> I agree.

I think the OP needs to be less opaque about what he actually did,
because the given example could not possibly have worked in any variant.
There is no provision in libpq for interpreting dbname as a
comma-separated list; therefore, what you actually get with the above
is a single attempt to connect to a database named
"xxxxx1,xxxxx2,xxxxx3,xxxxx4" (or "xxxxx2,xxxxx1,xxxxx3,xxxxx4" in
the allegedly-working case).

I assume that the actual test case involved a comma-separated *host*
(or hostaddr) list, which is what drives multiple connection attempts.
It is true that if we manage to make a connection to a host, but it
then rejects us for some reason, we just give up rather than trying
the next host. The problem with trying to improve that is that it's
very unclear which cases it's actually appropriate to do that for.
As an example, if you fat-finger the password to host 1, it's unlikely
that silently switching our attention to host 2 would be advisable.
At best, what you'd get is several confusing duplicate messages.

I experimented with letting PQconnectPoll retry after getting a server
error message, as per attached, but I thought the results were more
confusing than helpful.

regards, tom lane

Attachment Content-Type Size
retry-after-server-error-0.1.patch text/x-diff 1.3 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Noah Misch 2020-08-14 07:51:11 Re: BUG #16508: using multi-host connection string when the first host is starting fails
Previous Message Christoph Berg 2020-08-13 14:22:46 Re: BUG #16581: Corrupted debian repository