Re: libpq host/hostaddr/conninfo inconsistencies

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Cc: PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: libpq host/hostaddr/conninfo inconsistencies
Date: 2018-09-30 07:21:59
Message-ID: alpine.DEB.2.21.1809300826060.10583@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello Arthur,

Thanks for the comments.

>> However, the actual capability is slightly different: specifying an ip
>> address to "host" does work, without ensuing any name or reverse name
>> look-ups, even if this is undocumented.
> Agree it may have more details within the documentation.
>> sh> psql "host=/tmp hostaddr="
> Yeah this example shows that user may be confused by output of
> \conninfo. I think it is psql issue and libpq issue.

Yep. I'd add that there is a documentation issue as well.

> psql in exec_command_conninfo() rely only on the PQhost() result. Can we
> add a function PQhostType() to solve this issue?

I did not attempt to fix "\conninfo" yet, I focussed on the host/hostaddr
documentation and consistency checks in libpq.

I agree that at least one additional PQ function is needed.

What to do with a "host type" function is unclear, because it would not
change the output of PQhost() which returns the "host" value even if it
was ignored by the connection, there is no access to "hostaddr"... it is
not enough.

I was thinking that maybe a function could return the full description as
a string, so that the connection logic choices and display are implemented
in libpq only, but this is debatable.

Otherwise a collection of functions, including a host type function, would
be necessary for the client to have full information about the actual
current connection.

>> sh> psql "host= hostaddr="
> I'm not sure that is is the issue. User defined the host name and psql
> show it.

The issue is that "host" is an ip, "\conninfo" will inform wrongly that
you are connected to "", but the actual connection is really to
"", this is plain misleading, and I consider this level of
unhelpfullness more a bug than a feature.

>> sh> psql "hostaddr="
> I cannot reproduce it. It gives me the message:
> You are connected to database "artur" as user "artur" on host "" at port "5432".
> I think it is because of the environment (I didn't define PGHOST
> variable, for example). If so, depending on PGHOST variable value
> ("/tmp" or "") it is related with first or second issue.

Indeed, hostaddr superseedes the default, whatever it is, so it depends on
the default, which can be overriden with PGHOST.

>> * Another issue with \conninfo is that if a host resolves to multiple ips,
>> there is no way to know which was chosen and/or worked, although on errors
>> some messages show the failing ip.
> Can you explain it please? You can use PQhost() to know choosed host.

Indeed PQhost will tell the name. My point is that there will be no clue
about the actual ip used among those possible.

>> * The documentation about host/hostaddr/port accepting lists is really
>> added as an afterthought: the features are presented for one, and then the
>> list is mentionned.
> I cannot agree with you. When I've learned libpq before I found
> host/hostaddr rules description useful. And I disagree that it is good
> to remove it (as the patch does).
> Of course it is only my point of view and others may have another opinion.

I'm not sure I understand your concern.

Do you mean that you would prefer the document to keep describing that
host/hostaddr/port accepts one value, and then have in some other place or
at the end of the option documentation a line that say, "by the way, we
really accept lists, and they must be somehow consistent between

>> (3) checking that hostaddr non empty addresses are only accepted if the
>> corresponding host is a name. The user must use the "host=ip" syntax
>> to connect to an ip.

> Patch gives me an error if I specified only hostaddr:
> psql -d "hostaddr="
> psql: host "/tmp" cannot have an hostaddr ""

This is the expected modified behavior: hostaddr can only be specified on
a host when it is a name, which is not the case here.

Changing the name to "resolve", has it would maybe help the user realize
it is not expected to be used to provide the target host, it is just a dns

If the user wants to connect to, they have to use

> It is wrong, because I didn't specified host=/tmp.

You did not, but this is the default value when you do not specify "host"
explicitely, so it was specified behind your back.


In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Fabien COELHO 2018-09-30 07:23:50 Re: libpq host/hostaddr/conninfo inconsistencies
Previous Message Pavel Stehule 2018-09-30 06:23:39 Re: [HACKERS] [PATCH] Generic type subscripting