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

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: fix psql \conninfo & \connect when using hostaddr
Date: 2018-11-07 13:23:10
Message-ID: CAFj8pRBCOsQ2PKGwHoZrpircbO1DsaAd+53F9x4KOG0t6_ms1A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

pá 26. 10. 2018 v 15:55 odesílatel Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
napsal:

>
> Hello,
>
> This is a follow-up to another patch I posted about libpq confusing
> documentation & psql resulting behavior under host/hostaddr settings.
>
> Although the first mostly documentation patch did not gather much
> enthousiasm, I still think both issues deserve a fix.
>
> About updating psql's behavior, without this patch:
>
> sh> psql "host=foo hostaddr=127.0.0.1"
>
> psql> \conninfo
> You are connected to database "fabien" as user "fabien" on host "foo"
> at port "5432".
> # NOPE, I'm really connected to localhost, foo does not even exist
> # Other apparent inconsistencies are possible when hostaddr overrides
> # "host" which is an socket directory or an IP.
>
> psql> \c template1
> could not translate host name "foo" to address: Name or service not
> known
> Previous connection kept
> # hmmm.... what is the meaning of reusing a connection?
> # this issue was pointed out by Arthur Zakirov
>
> After the patch:
>
> sh> psql "host=foo hostaddr=127.0.0.1"
>
> psql> \conninfo
> You are connected to database "fabien" as user "fabien" on host "foo"
> (address "127.0.0.1") at port "5432".
> # better
>
> psql> \c template1
> You are now connected to database "template1" as user "fabien".
> # thanks
>
> The patch adds a PQhostaddr() function to libpq which reports the
> "hostaddr" setting or the current server ip. The function is used by psql
> for \conninfo and when reusing parameters for \connect.
>
> The messages are slightly more verbose because the IP is output. I think
> that user asking for conninfo should survive to the more precise data.
> This also comes handy if a host name resolves to several IPs (eg IPv6 and
> IPv4, or several IPs...).
>
>
I checked this patch, and it looks well. The documentation is correct, all
tests passed. It does what is proposed.

I think so some redundant messages can be reduced - see function
printConnInfo - attached patch

If there are no be a objection, I'll mark this patch as ready for commiters

Regards

Pavel

> --
> Fabien.

Attachment Content-Type Size
libpq-conn-2.patch text/x-patch 10.8 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jesper Pedersen 2018-11-07 13:25:28 Re: valgrind on initdb
Previous Message Daniel Gustafsson 2018-11-07 13:21:59 Re: Support custom socket directory in pg_upgrade