Re: fix psql \conninfo & \connect when using hostaddr

Fabien COELHO <coelho@cri.ensmp.fr>

From: Fabien COELHO <coelho@cri.ensmp.fr>
To: Noah Misch <noah@leadboat.com>
Cc: Dmitry Dolgov <9erthalion6@gmail.com>, Alvaro Herrera <alvherre@2ndquadrant.com>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>, Arthur Zakirov <a.zakirov@postgrespro.ru>, Robert Haas <robertmhaas@gmail.com>
Date: 2019-06-12T12:44:49Z
Lists: pgsql-hackers

Attachments

Hello,

> I got that. I'm working on it, and on the other issues you raised.
>
> The issue I see is what do we want when a name resolves to multiple 
> addresses. The answer is not fully obvious to me right now. I'll try to send 
> a patch over the week-end.

At Alvaro's request, here is a quick WIP patch, that does not do the right 
thing, because there is no simple way to know whether hostaddr was set at 
the libPQ level, so either we set it always, about which Noah complained, 
or we don't, about which someone else will complain quite easily, i.e. 
with this patch

   \c "host=foo hostaddr=ip"

connects to ip, but then

   \c

will reconnect to foo but ignore ip. Well, ISTM that this is back to the 
previous doubtful behavior, so at least it is not a regression, just the 
same bug:-)

A solution could be to have a PQdoestheconnectionuseshostaddr(conn) 
function, but I cannot say I'd be thrilled.

Another option would be to import PGconn full definition in 
"psql/command.c", but that would break the PQ interface, I cannot say I'd 
be thrilled either.

The patch returns host as defined by the user, but the regenerated 
hostaddr (aka connip), which is not an homogeneous behavior. PQhost should 
probably use connip if host was set as an ip, but that needs guessing.

The underlying issue is that the host/hostaddr stuff is not that easy to 
fix.

At least, after the patch the connection information (\conninfo) is still 
the right one, which is an improvement.

-- 
Fabien.

Commits

  1. Tweak libpq's PQhost, PQhostaddr, and psql's \connect

  2. psql: Show IP address in \conninfo