From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Allow psql to re-use connection parameters after a connection lo
Date: Fri, 23 Oct 2020 21:07:23 +0000
Message-ID: <E1kW4HT-0003sK-Mb@gemulon.postgresql.org> (raw)
Allow psql to re-use connection parameters after a connection loss.
Instead of immediately PQfinish'ing a dead connection, save it aside
so that we can still extract its parameters for \connect attempts.
(This works because PQconninfo doesn't care whether the PGconn is in
CONNECTION_BAD state.) This allows developers to reconnect with
just \c after a database crash and restart.
It's tempting to use the same approach instead of closing the old
connection after a failed non-interactive \connect command. However,
that would not be very safe: 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.
Discussion: https://postgr.es/m/38464.1603394584@sss.pgh.pa.us
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/1b62d0fb3e50ede570d0d4e4a2be69d5645b48a7
Modified Files
--------------
doc/src/sgml/ref/psql-ref.sgml | 17 ++++++++++---
src/bin/psql/command.c | 57 +++++++++++++++++++++++++++++-------------
src/bin/psql/common.c | 10 +++++---
src/bin/psql/describe.c | 2 +-
src/bin/psql/settings.h | 7 ++++++
src/bin/psql/startup.c | 6 ++++-
6 files changed, 73 insertions(+), 26 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Allow psql to re-use connection parameters after a connection lo
In-Reply-To: <E1kW4HT-0003sK-Mb@gemulon.postgresql.org>
References: <E1kW4HT-0003sK-Mb@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox