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

From: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
To: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
Cc: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Arthur 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-19 15:53:15
Message-ID: 20181119155315.vsrgj2droozqgfqo@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On 2018-Nov-17, Fabien COELHO wrote:

> Here is the updated v2
> - libpq internal function getHostaddr get a length,
> and I added an assert about it.
> - added a few braces on if/if/else/if/else/else
> - added an UNKNOWN_HOST macro to hide "???"
> - moved host_addr[] declaration earlier to avoid some braces

You forgot to free(conn->connip) during freePGconn().

I found the UNKNOWN_HOST business quite dubious -- not only in your
patch but also in the existing coding. I changed the getHostname API so
that instead of returning "???" it sets the output buffer to the empty
string. AFAICS the only user-visible behavior is that we no longer
display the "???" in a parenthical comment next to the server address
when a connection fails (this is pre-existing behavior, not changed by
your patch.)

Now, maybe the thinking was that upon seeing this message:

could not connect to server: some error here
Is the server running on host "" (???) and accepting
connections on port 5432?

the user was going to think "oh, my machine must have run out of memory,
I'll reboot and retry". However, I highly doubt that anybody would
reach that conclusion without reading the source code. So I deem this

Álvaro Herrera
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Attachment Content-Type Size
0001-psql-Show-IP-address-in-conninfo-if-different-from-h.patch text/x-diff 13.6 KB

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Dmitry Dolgov 2018-11-19 15:58:45 Re: Reviving the "Stopping logical replication protocol" patch from Vladimir Gordichuk
Previous Message Stephen Frost 2018-11-19 15:39:15 Re: your mail