Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1efu94-0007Xw-6P for pgsql-bugs@arkaria.postgresql.org; Sun, 28 Jan 2018 21:05:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1efu92-0003Es-GR for pgsql-bugs@arkaria.postgresql.org; Sun, 28 Jan 2018 21:05:44 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1efu92-0003Ej-7B for pgsql-bugs@lists.postgresql.org; Sun, 28 Jan 2018 21:05:44 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1efu8z-0002eb-SI for pgsql-bugs@lists.postgresql.org; Sun, 28 Jan 2018 21:05:43 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w0SL5ehW016152; Sun, 28 Jan 2018 16:05:40 -0500 From: Tom Lane To: Bruce Momjian cc: akos@elegran.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15025: PSQL CLI - inconsistency when both -d and -U supplies a username In-reply-to: <20180128203633.GC4380@momjian.us> References: <20180123130013.7407.24749@wrigleys.postgresql.org> <20180128034832.GD9153@momjian.us> <29202.1517168326@sss.pgh.pa.us> <20180128200418.GA4380@momjian.us> <14400.1517171454@sss.pgh.pa.us> <20180128203633.GC4380@momjian.us> Comments: In-reply-to Bruce Momjian message dated "Sun, 28 Jan 2018 15:36:33 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <16150.1517173540.1@sss.pgh.pa.us> Date: Sun, 28 Jan 2018 16:05:40 -0500 Message-ID: <16151.1517173540@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Bruce Momjian writes: > Oh, I wasn't aware a failed login left us with a 'conn'. Sure, it's what's carrying the error message. But it's also got all the actual connection parameters filled in. After further experimentation it seems like the has_connection_string logic in do_connect() causes the \c case to behave pretty much as you'd want: $ psql -U user1 -d "postgresql://user2@localhost/postgres" -W Password: postgres=> \c - Password for user user2: You are now connected to database "postgres" as user "user2". postgres=> \c postgresql://user1@localhost/postgres Password: You are now connected to database "postgres" as user "user1". So I now think the comment I added to do_connect() is unduly pessimistic, and it's fine to keep using "prompt_for_password(user)" for a forced password prompt there. There may still be use-cases where it gets it wrong, but they're too narrow to be worth giving up the helpful prompt altogether. regards, tom lane