Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T1mfL-0003G1-0V for pgsql-bugs@postgresql.org; Wed, 15 Aug 2012 23:06:19 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1T1mfI-0003uv-TJ for pgsql-bugs@postgresql.org; Wed, 15 Aug 2012 23:06:18 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1T1mfE-0001C0-Ta; Wed, 15 Aug 2012 19:06:12 -0400 Date: Wed, 15 Aug 2012 19:06:12 -0400 From: Bruce Momjian To: Robert Haas Cc: Peter Eisentraut , depesz@depesz.com, Tom Lane , pgsql-bugs@postgresql.org Subject: Re: psql doesn't reuse -p after backend fail Message-ID: <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> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="+JUInw4efm7IfTNU" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201208/113 X-Sequence-Number: 33837 --+JUInw4efm7IfTNU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Sep 14, 2011 at 10:52:50PM -0500, Robert Haas wrote: > On Thu, Sep 8, 2011 at 5:09 AM, Peter Eisentraut 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 http://momjian.us EnterpriseDB http://enterprisedb.com + It's impossible for everything to be true. + --+JUInw4efm7IfTNU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="psql.diff" diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c new file mode 100644 index 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) --+JUInw4efm7IfTNU--