Mop-up around psql's \connect behavior
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Date: 2020-10-21T22:59:04Z
Lists: pgsql-hackers
Attachments
- minor-fixes-for-psql-connect.patch (text/x-diff) patch
While working on commit 85c54287a, I noticed a few things I did not much care for in do_connect(). These don't quite seem to rise to the level of back-patchable bugs, but they're still not great: * The initial stanza that complains about if (!o_conn && (!dbname || !user || !host || !port)) seems woefully obsolete. In the first place, it's pretty silly to equate a "complete connection specification" with having just those four values; the whole point of 85c54287a and predecessors is that other settings such as sslmode may be just as important. In the second place, this fails to consider the possibility that we only have a connstring parameter --- which may nonetheless provide all the required settings. And in the third place, this clearly wasn't revisited when we added explicit control of whether or not we're supposed to re-use parameters from the old connection. It's very silly to insist on having an o_conn if we're going to ignore it anyway. I think the reason we've not had complaints about this is that the situation normally doesn't arise in interactive sessions (since we won't release the old connection voluntarily), while scripts are likely not designed to cope with connection losses anyway. These facts militate against spending a whole lot of effort on a fix, but still we ought to reduce the silliness factor. What I propose is to complain if we have no o_conn *and* we are asked to re-use parameters from it. Otherwise, it's fine. * I really don't like the bit about silently ignoring user, host, and port parameters if we see that the first parameter is a connstring. That's as user-unfriendly as can be. It should be a syntax error to specify both; the documentation certainly implies that it is. * The old-style-syntax code path understands that it should re-use the old password (if any) when the user, host, and port settings haven't changed. The connstring code path was too lazy to make that work, but now that we're deconstructing the connstring there's very little excuse for not having it act the same way. The attached patch fixes these things and documents the password behavior, which for some reason went unmentioned before. Along the way I simplified the mechanism for re-using a password a bit; there's no reason to treat it so much differently from re-using other parameters. Any objections? regards, tom lane
Commits
-
Allow psql to re-use connection parameters after a connection loss.
- 1b62d0fb3e50 14.0 landed
-
Clean up some unpleasant behaviors in psql's \connect command.
- 94929f1cf6cb 14.0 landed
-
Fix connection string handling in psql's \connect command.
- 85c54287af56 14.0 cited