pgsql: In libpq, don't look up all the hostnames at once. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: In libpq, don't look up all the hostnames at once.
Date
Msg-id E1fswOe-0001AZ-Nn@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
In libpq, don't look up all the hostnames at once.

Historically, we looked up the target hostname in connectDBStart, so that
PQconnectPoll did not need to do DNS name resolution.  The patches that
added multiple-target-host support to libpq preserved this division of
labor; but it's really nonsensical now, because it means that if any one
of the target hosts fails to resolve in DNS, the connection fails.  That
negates the no-single-point-of-failure goal of the feature.  Additionally,
DNS lookups aren't exactly cheap, but the code did them all even if the
first connection attempt succeeds.

Hence, rearrange so that PQconnectPoll does the lookups, and only looks
up a hostname when it's time to try that host.  This does mean that
PQconnectPoll could block on a DNS lookup --- but if you wanted to avoid
that, you should be using hostaddr, as the documentation has always
specified.  It seems fairly unlikely that any applications would really
care whether the lookup occurs inside PQconnectStart or PQconnectPoll.

In addition to calling out that fact explicitly, do some other minor
wordsmithing in the docs around the multiple-target-host feature.

Since this seems like a bug in the multiple-target-host feature,
backpatch to v10 where that was introduced.  In the back branches,
avoid moving any existing fields of struct pg_conn, just in case
any third-party code is looking into that struct.

Tom Lane, reviewed by Fabien Coelho

Discussion: https://postgr.es/m/4913.1533827102@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/5ca00774194dc179d02867d536b73eb85fffd227

Modified Files
--------------
doc/src/sgml/libpq.sgml           |  78 +++++++-----
src/interfaces/libpq/fe-connect.c | 249 ++++++++++++++++++--------------------
src/interfaces/libpq/libpq-int.h  |   5 +-
3 files changed, 164 insertions(+), 168 deletions(-)


pgsql-committers by date:

Previous
From: Peter Eisentraut
Date:
Subject: pgsql: Copy-editing of pg_verify_checksums help and ref page
Next
From: Andrew Gierth
Date:
Subject: pgsql: Reduce an unnecessary O(N^3) loop in lexer.