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

From: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
To: Noah Misch <noah(at)leadboat(dot)com>
Cc: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>, Fabien COELHO <coelho(at)cri(dot)ensmp(dot)fr>, 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: 2019-06-10 18:22:32
Message-ID: CA+q6zcW05NPgT+AnWOC3X1Vd0tnRhVYkL5jR6yAk+1DrFS9AyA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Mon, May 27, 2019 at 10:38 PM Noah Misch <noah(at)leadboat(dot)com> wrote:
>
> On Mon, Nov 19, 2018 at 12:53:15PM -0300, Alvaro Herrera wrote:
> > commit 6e5f8d4
> > Commit: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
> > CommitDate: Mon Nov 19 14:34:12 2018 -0300
> >
> > psql: Show IP address in \conninfo
>
> > Discussion: https://postgr.es/m/alpine.DEB.2.21.1810261532380.27686@lancre
> > https://postgr.es/m/alpine.DEB.2.21.1808201323020.13832@lancre
>
> > --- a/src/bin/psql/command.c
> > +++ b/src/bin/psql/command.c
> > @@ -2894,12 +2911,27 @@ do_connect(enum trivalue reuse_previous_specification,
> > }
> >
> > /* grab missing values from the old connection */
> > - if (!user && reuse_previous)
> > - user = PQuser(o_conn);
> > - if (!host && reuse_previous)
> > - host = PQhost(o_conn);
> > - if (!port && reuse_previous)
> > - port = PQport(o_conn);
> > + if (reuse_previous)
> > + {
> > + if (!user)
> > + user = PQuser(o_conn);
> > + if (host && strcmp(host, PQhost(o_conn)) == 0)
> > + {
> > + /*
> > + * if we are targetting the same host, reuse its hostaddr for
> > + * consistency
> > + */
> > + hostaddr = PQhostaddr(o_conn);
> > + }
> > + if (!host)
> > + {
> > + host = PQhost(o_conn);
> > + /* also set hostaddr for consistency */
> > + hostaddr = PQhostaddr(o_conn);
> > + }
> > + if (!port)
> > + port = PQport(o_conn);
> > + }
> >
> > /*
> > * Any change in the parameters read above makes us discard the password.
>
> The "hostaddr = PQhostaddr(o_conn)" branches make \connect use the same IP
> address as the existing connection. I like that when the existing connection
> uses a hostaddr= parameter, but I doubt it's the right thing otherwise. If
> the server IP changes, \connect should find the server at its new IP. If the
> server has multiple IPs, \connect should have the opportunity to try them all,
> just like the original connection attempt could have.
>
> Other than that, the \connect behavior change makes sense to me. However,
> nothing updated \connect documentation. (Even the commit log message said
> nothing about \connect.)

Given that it's an open item for PostgreSQL 12, I've decided to take a look.
Indeed, looks like 6e5f8d4 introduced a subtle behaviour change, when hostaddr
changes are not picked up for subsequent \connect's, and I don't see any
mentions of it in the documentation. Although I guess it can be avoided by
`-reuse-previous=off`, probably it makese sense to update the docs.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message - - 2019-06-10 18:22:41 Re: Temp table handling after anti-wraparound shutdown (Was: BUG #15840)
Previous Message Alexander Korotkov 2019-06-10 17:33:38 Re: doc: pg_trgm missing description for GUC "pg_trgm.strict_word_similarity_threshold"