]> granicus.if.org Git - postgresql/blobdiff - src/bin/psql/command.c
Handle corner cases correctly in psql's reconnection logic.
[postgresql] / src / bin / psql / command.c
index c0a7a5566eb2a3c81a543c727591c2822f871fb5..93953fc8e7d961715d366e7db31364de53697a55 100644 (file)
@@ -3120,8 +3120,14 @@ do_connect(enum trivalue reuse_previous_specification,
                        pg_log_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();
                        }
                }
 
@@ -3135,7 +3141,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;
@@ -3226,7 +3233,8 @@ connection_warnings(bool in_startup)
                                                                                 sverbuf, sizeof(sverbuf)));
 
 #ifdef WIN32
-               checkWin32Codepage();
+               if (in_startup)
+                       checkWin32Codepage();
 #endif
                printSSLInfo();
                printGSSInfo();