diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 4aaf657cce8..40eba61b37c 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -1970,8 +1970,14 @@ do_connect(enum trivalue reuse_previous_specification, psql_error("\\connect: %s", PQerrorMessage(n_conn)); if (o_conn) { + /* + * Transition to having no connection. Keep this bit in sync + * with CheckConnection(). + */ PQfinish(o_conn); pset.db = NULL; + ResetCancelConn(); + UnsyncVariables(); } } @@ -1985,7 +1991,8 @@ do_connect(enum trivalue reuse_previous_specification, /* * Replace the old connection with the new one, and update - * connection-dependent variables. + * connection-dependent variables. Keep the resynchronization logic in + * sync with CheckConnection(). */ PQsetNoticeProcessor(n_conn, NoticeProcessor, NULL); pset.db = n_conn; @@ -2060,7 +2067,8 @@ connection_warnings(bool in_startup) sverbuf, sizeof(sverbuf))); #ifdef WIN32 - checkWin32Codepage(); + if (in_startup) + checkWin32Codepage(); #endif printSSLInfo(); } diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index a5e42973de8..5eea2272922 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -378,13 +378,27 @@ CheckConnection(void) if (!OK) { psql_error("Failed.\n"); + + /* + * Transition to having no connection. Keep this bit in sync with + * do_connect(). + */ PQfinish(pset.db); pset.db = NULL; ResetCancelConn(); UnsyncVariables(); } else + { psql_error("Succeeded.\n"); + + /* + * Re-sync, just in case anything changed. Keep this in sync with + * do_connect(). + */ + SyncVariables(); + connection_warnings(false); /* Must be after SyncVariables */ + } } return OK;