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

From: Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Artur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>
Subject: Re: fix psql \conninfo & \connect when using hostaddr
Date: 2018-11-08 10:54:27
Message-ID: alpine.DEB.2.21.1811081107130.22503@lancre
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Hello Robert,

>> psql> \conninfo
>> You are connected to database "fabien" as user "fabien" on host "foo" at port "5432".
>
> I remain of the opinion that this is not a bug. You told it that foo
> has address 127.0.0.1 and it believed you; that's YOUR fault.

Hmmm. For me, if a user asks \conninfo for connection information, they
expect to be told what the connection actually is, regardless of the
initial connection string.

Another more stricking instance:

sh> psql "host=/tmp port=5432 hostaddr=127.0.0.1"
...
fabien=# \conninfo
You are connected to database "fabien" as user "fabien" via socket in "/tmp" at port "5432".
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)

It says that there is a socket, but there is none. The SSL bit is a
giveaway, there is no SSL on Unix-domain sockets.

>> 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".
>
> Nevertheless, that seems like a reasonable change to the output. Will
> your patch show the IP address in all cases or only when hostaddr is
> specified?

It is always printed, unless both host & address are equal.

The rational is that it is also potentially useful for multi-ip dns
resolutions, and generating a valid hostaddr allows \connect defaults to
reuse the actual same connection, including the IP that was chosen.

Also, the added information is quite short, and if a user explicitely asks
for connection information, I think they can handle the slightly expanded
answer.

--
Fabien.

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2018-11-08 11:08:25 Re: Resetting PGPROC atomics in ProcessInit()
Previous Message Yuzuko Hosoya 2018-11-08 10:19:14 A typo in partprune.c