pgsql: psql: fix \connect with URIs and conninfo strings

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: psql: fix \connect with URIs and conninfo strings
Date: 2015-04-01 23:10:02
Message-ID: E1YdRlq-0001NF-Gw@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

psql: fix \connect with URIs and conninfo strings

psql was already accepting conninfo strings as the first parameter in
\connect, but the way it worked wasn't sane; some of the other
parameters would get the previous connection's values, causing it to
connect to a completely unexpected server or, more likely, not finding
any server at all because of completely wrong combinations of
parameters.

Fix by explicitely checking for a conninfo-looking parameter in the
dbname position; if one is found, use its complete specification rather
than mix with the other arguments. Also, change tab-completion to not
try to complete conninfo/URI-looking "dbnames" and document that
conninfos are accepted as first argument.

There was a weak consensus to backpatch this, because while the behavior
of using the dbname as a conninfo is nowhere documented for \connect, it
is reasonable to expect that it works because it does work in many other
contexts. Therefore this is backpatched all the way back to 9.0.

To implement this, routines previously private to libpq have been
duplicated so that psql can decide what looks like a conninfo/URI
string. In back branches, just duplicate the same code all the way back
to 9.2, where URIs where introduced; 9.0 and 9.1 have a simpler version.
In master, the routines are moved to src/common and renamed.

Author: David Fetter, Andrew Dunstan. Some editorialization by me
(probably earning a Gierth's "Sloppy" badge in the process.)
Reviewers: Andrew Gierth, Erik Rijkers, Pavel Stěhule, Stephen Frost,
Robert Haas, Andrew Dunstan.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/fcef1617295c074f2684c887627184d2fc26ac04

Modified Files
--------------
doc/src/sgml/ref/psql-ref.sgml | 40 ++++++++++++++-----
src/bin/psql/command.c | 80 ++++++++++++++++++++++++++-----------
src/bin/psql/help.c | 4 +-
src/bin/psql/tab-complete.c | 13 +++++-
src/common/Makefile | 2 +-
src/common/connstrings.c | 53 ++++++++++++++++++++++++
src/include/common/connstrings.h | 16 ++++++++
src/interfaces/libpq/fe-connect.c | 46 +++------------------
8 files changed, 175 insertions(+), 79 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Michael Paquier 2015-04-02 01:29:03 Re: pgsql: psql: fix \connect with URIs and conninfo strings
Previous Message Bruce Momjian 2015-04-01 22:25:51 pgsql: pg_upgrade: call 'postgres' binary to get data directory locati