Fix psql's \connect command some more.
authorTom Lane <[email protected]>
Tue, 23 Mar 2021 18:27:50 +0000 (14:27 -0400)
committerTom Lane <[email protected]>
Tue, 23 Mar 2021 18:27:50 +0000 (14:27 -0400)
commitd5a905ed5e7b277392db6c07efd40ec2ba9e6341
tree0cdc9caae77994502eabc5d5aabc011a5c7c15c4
parentfb742ce2687a9fdb103479950603cfbecbed285e
Fix psql's \connect command some more.

Jasen Betts reported yet another unintended side effect of commit
85c54287a: reconnecting with "\c service=whatever" did not have the
expected results.  The reason is that starting from the output of
PQconndefaults() effectively allows environment variables (such
as PGPORT) to override entries in the service file, whereas the
normal priority is the other way around.

Not using PQconndefaults at all would require yet a third main code
path in do_connect's parameter setup, so I don't really want to fix
it that way.  But we can have the logic effectively ignore all the
default values for just a couple more lines of code.

This patch doesn't change the behavior for "\c -reuse-previous=on
service=whatever".  That remains significantly different from before
85c54287a, because many more parameters will be re-used, and thus
not be possible for service entries to replace.  But I think this
is (mostly?) intentional.  In any case, since libpq does not report
where it got parameter values from, it's hard to do differently.

Per bug #16936 from Jasen Betts.  As with the previous patches,
back-patch to all supported branches.  (9.5 is unfortunately now
out of support, so this won't get fixed there.)

Discussion: https://postgr.es/m/16936-3f524322a53a29f0@postgresql.org
src/bin/psql/command.c