psql bug -- using old variables and database connection

Lists: pgsql-hackers
From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: Postgres <pgsql-hackers(at)postgresql(dot)org>
Subject: psql bug -- using old variables and database connection
Date: 2008-08-12 09:10:51
Message-ID: 87wsimwqck.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


We're currently printing the warning about connecting to the wrong version of
the server *before* syncing variables. On reconnecting this results in using
the *old* server version before reconnecting. I'm not sure what happens for
the initial connection but it can't be good. connection_warnings also uses
pset.db which isn't set until a few lines later too which can't be good.

e.g.

postgres=# \c
psql (8.4devel)
You are now connected to database "postgres".
postgres=# select version();
version
-----------------------------------------------------------------------------------------
PostgreSQL 8.2.5 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.2.1 (Debian 4.2.1-5)
(1 row)

postgres=# \c
psql (8.4devel, server 8.2.5)
WARNING: psql version 8.4, server version 8.2.
Some psql features might not work.
You are now connected to database "postgres".

--- command.c 30 Jul 2008 21:57:07 +0100 1.192
+++ command.c 12 Aug 2008 10:05:52 +0100
@@ -1197,10 +1197,10 @@
* Replace the old connection with the new one, and update
* connection-dependent variables.
*/
- connection_warnings();
PQsetNoticeProcessor(n_conn, NoticeProcessor, NULL);
pset.db = n_conn;
SyncVariables();
+ connection_warnings(); /* Must be after SyncVariables */

/* Tell the user about the new connection */
if (!pset.quiet)

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Get trained by Bruce Momjian - ask me about EnterpriseDB's PostgreSQL training!


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: Postgres <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: psql bug -- using old variables and database connection
Date: 2008-08-16 00:17:07
Message-ID: 200808160017.m7G0H7f27983@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Thanks, applied.

---------------------------------------------------------------------------

Gregory Stark wrote:
>
> We're currently printing the warning about connecting to the wrong version of
> the server *before* syncing variables. On reconnecting this results in using
> the *old* server version before reconnecting. I'm not sure what happens for
> the initial connection but it can't be good. connection_warnings also uses
> pset.db which isn't set until a few lines later too which can't be good.
>
> e.g.
>
> postgres=# \c
> psql (8.4devel)
> You are now connected to database "postgres".
> postgres=# select version();
> version
> -----------------------------------------------------------------------------------------
> PostgreSQL 8.2.5 on i686-pc-linux-gnu, compiled by GCC gcc (GCC) 4.2.1 (Debian 4.2.1-5)
> (1 row)
>
> postgres=# \c
> psql (8.4devel, server 8.2.5)
> WARNING: psql version 8.4, server version 8.2.
> Some psql features might not work.
> You are now connected to database "postgres".
>
>
>
>
> --- command.c 30 Jul 2008 21:57:07 +0100 1.192
> +++ command.c 12 Aug 2008 10:05:52 +0100
> @@ -1197,10 +1197,10 @@
> * Replace the old connection with the new one, and update
> * connection-dependent variables.
> */
> - connection_warnings();
> PQsetNoticeProcessor(n_conn, NoticeProcessor, NULL);
> pset.db = n_conn;
> SyncVariables();
> + connection_warnings(); /* Must be after SyncVariables */
>
> /* Tell the user about the new connection */
> if (!pset.quiet)
>
>
> --
> Gregory Stark
> EnterpriseDB http://www.enterprisedb.com
> Get trained by Bruce Momjian - ask me about EnterpriseDB's PostgreSQL training!
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +