Re: libpq async connection and multiple hosts - Mailing list pgsql-hackers

From Jelte Fennema
Subject Re: libpq async connection and multiple hosts
Date
Msg-id CAGECzQSrSB2EL=vH53gpQFs=RVQZu7G341zxk3TYebVnZbNWuw@mail.gmail.com
Whole thread Raw
In response to libpq async connection and multiple hosts  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
Responses Re: libpq async connection and multiple hosts
Re: libpq async connection and multiple hosts
List pgsql-hackers
On Wed, 25 Oct 2023 at 17:03, Daniele Varrazzo
<daniele.varrazzo@gmail.com> wrote:
> However, ISTM that connecting to multiple hosts is not supported
> either. I have a couple of issues I am looking into in psycopg 3:
>
> - https://github.com/psycopg/psycopg/issues/602
> - https://github.com/psycopg/psycopg/issues/674

Another approach is to use tcp_user_timeout instead of connect_timeout
to skip non-responsive hosts. It's not completely equivalent though to
connection_timeout though, since it also applies when the connection
is actually being used. Also it only works on Linux afaik. It could be
nice to add support for BSD its TCP_CONNECTIONTIMEOUT socket option.

> Do we have to reimplement the connection attempts loop too?

If you want to support connection_timeout, it seems yes.

> Are there other policies that we would need to reimplement? Is
> `target_session_attrs` taken care of by PQconnectPoll?

Afaict from the code target_session_attrs are handled inside
PQconnectPoll, so you would not have to re-implement that.
PQconnectPoll would simply fail if target_session_attrs don't match
for the server. You should implement load_balance_hosts=random though
by randomizing your hosts list.



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: trying again to get incremental backup
Next
From: Andrei Zubkov
Date:
Subject: Re: [PATCH] Tracking statements entry timestamp in pg_stat_statements