summaryrefslogtreecommitdiff
path: root/src/bin/psql/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/psql/common.c')
-rw-r--r--src/bin/psql/common.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 6323a35c91c..ff673665d86 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -313,10 +313,14 @@ CheckConnection(void)
fprintf(stderr, _("Failed.\n"));
/*
- * Transition to having no connection. Keep this bit in sync with
- * do_connect().
+ * Transition to having no connection; but stash away the failed
+ * connection so that we can still refer to its parameters in a
+ * later \connect attempt. Keep the state cleanup here in sync
+ * with do_connect().
*/
- PQfinish(pset.db);
+ if (pset.dead_conn)
+ PQfinish(pset.dead_conn);
+ pset.dead_conn = pset.db;
pset.db = NULL;
ResetCancelConn();
UnsyncVariables();