From: Bruce Momjian <bruce@momjian.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Peter Eisentraut <peter_e@gmx.net>
Cc: depesz@depesz.com
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: psql doesn't reuse -p after backend fail
Date: Wed, 15 Aug 2012 19:06:12 -0400
Message-ID: <20120815230612.GT25473@momjian.us> (raw)
In-Reply-To: <CA+TgmoZ10jzgLsEaN=80Na9_orTG=8F2u23gaqw9xjYmRq736w@mail.gmail.com>
References: <20110905174633.GA7752@depesz.com>
<11444.1315247243@sss.pgh.pa.us>
<20110906151253.GA1209@depesz.com>
<1315476562.17143.0.camel@fsopti579.F-Secure.com>
<CA+TgmoZ10jzgLsEaN=80Na9_orTG=8F2u23gaqw9xjYmRq736w@mail.gmail.com>
On Wed, Sep 14, 2011 at 10:52:50PM -0500, Robert Haas wrote:
> On Thu, Sep 8, 2011 at 5:09 AM, Peter Eisentraut <peter_e@gmx.net> wrote:
> > On tis, 2011-09-06 at 17:12 +0200, hubert depesz lubaczewski wrote:
> >> On Mon, Sep 05, 2011 at 02:27:23PM -0400, Tom Lane wrote:
> >> > It's not just the port, it's all the connection parameters ---
> >> > do_connect relies on the PGconn object to remember those, and in this
> >> > case there no longer is a PGconn object.
> >> >
> >> > We could have psql keep that information separately, but I'm not sure
> >> > it's really worth the trouble.
> >>
> >> well, I think it's definitely worth the trouble. If I had datbaase
> >> standing at 5432, it would connect to it, and then I could mistakenly
> >> ran commands to wrong database.
> >> this is clearly not a good thing.
> >
> > Perhaps just prevent \connect without argument if the information is no
> > longer available.
>
> I think it'd be worth actually having psql maintain the information
> separately from the PGconn... but if nobody feels motivated to go do
> that, doing at least this much would remove the foot-gun. So +1 for
> that.
OK, I have applied the attached, applied patch to do as you suggest.
Here are examples:
!> SELECT * FROM mytable WHERE to_ascii(convert_to(mytext, 'latin1'), 'latin1')
-> = to_ascii(convert_to('nicetry', 'latin1'), 'latin1');
You are currently not connected to a database.
!> \c
All connection parameters must be supplied because no database connection exists
!> \q
$ psql -p 5433 test
psql (9.3devel)
Type "help" for help.
test=> \c
You are now connected to database "test" as user "postgres".
test=> \q
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
Attachments:psql.diff (text/x-diff, 558B) downloaddiff --git a/src/bin/psql/command.c b/src/bin/psql/command.cnew file mode 100644index 6ead800..2cd3ab4
*** a/src/bin/psql/command.c
--- b/src/bin/psql/command.c
*************** do_connect(char *dbname, char *user, cha
*** 1512,1517 ****
--- 1512,1523 ----
*n_conn;
char *password = NULL;
+ if (!o_conn && (!dbname || !user || !host || !port))+ {+ fputs(_("All connection parameters must be supplied because no database connection exists\n"), stderr);+ return false;+ }+
if (!dbname)
dbname = PQdb(o_conn);
if (!user)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: bruce@momjian.us, robertmhaas@gmail.com, peter_e@gmx.net, depesz@depesz.com, tgl@sss.pgh.pa.us
Subject: Re: psql doesn't reuse -p after backend fail
In-Reply-To: <20120815230612.GT25473@momjian.us>
References: <20110905174633.GA7752@depesz.com> <11444.1315247243@sss.pgh.pa.us> <20110906151253.GA1209@depesz.com> <1315476562.17143.0.camel@fsopti579.F-Secure.com> <CA+TgmoZ10jzgLsEaN=80Na9_orTG=8F2u23gaqw9xjYmRq736w@mail.gmail.com> <20120815230612.GT25473@momjian.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox