Re: Mop-up around psql's \connect behavior - Mailing list pgsql-hackers

From Kyotaro Horiguchi
Subject Re: Mop-up around psql's \connect behavior
Date
Msg-id 20201026.095141.2074927425822627268.horikyota.ntt@gmail.com
Whole thread Raw
In response to Re: Mop-up around psql's \connect behavior  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
At Fri, 23 Oct 2020 17:12:44 -0400, Tom Lane <tgl@sss.pgh.pa.us> wrote in 
> Kyotaro Horiguchi <horikyota.ntt@gmail.com> writes:
> > At Thu, 22 Oct 2020 15:23:04 -0400, Tom Lane <tgl@sss.pgh.pa.us> wrote in 
> >> ... The only real objection I can see is that it could
> >> hold a server connection open when the user thinks there is none;
> >> but that could only happen in a non-interactive script, and it does
> >> not seem like a big problem in that case.  We could alternatively
> >> not stash the "dead" connection after a non-interactive \connect
> >> failure, but I doubt that's better.
> 
> > Agreed. Thanks!
> 
> After further thought I decided we *must* do it as per my "alternative"
> idea.  Consider a script containing
>     \c db1 user1 live_server
>     \c db2 user2 dead_server
>     \c db3
> The script would be expecting to connect to db3 at dead_server, but
> if we re-use parameters from the first connection then it might
> successfully connect to db3 at live_server.  This'd defeat the goal
> of not letting a script accidentally execute commands against the
> wrong database.

Hmm. True.

> So we have to not save the connection after a failed script \connect.

Yes, we shouldn't save a connection parameters that haven't made a
connection.

> However, it seems OK to save after a connection loss whether we're
> in a script or not; that is,
> 
>     \c db1 user1 server1
>     ...
>     (connection dies here)
>     ...  --- these commands will fail
>     \c db2
> 
> The script will be expecting the second \c to re-use parameters
> from the first one, and that will still work as expected.

Agreed.

> I went ahead and pushed it after adjusting that.

Thanks!

-- 
Kyotaro Horiguchi
NTT Open Source Software Center



pgsql-hackers by date:

Previous
From: Justin Pryzby
Date:
Subject: Re: Allow deleting enum value
Next
From: Alexander Korotkov
Date:
Subject: Re: MultiXact\SLRU buffers configuration