On Wed, 25 Oct 2023 at 17:03, Daniele Varrazzo <daniele.varra...@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.