Re: Removing support for COPY FROM STDIN in protocol version 2

Heikki Linnakangas <hlinnaka@iki.fi>

From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Michael Paquier <michael@paquier.xyz>, Alvaro Herrera <alvherre@alvh.no-ip.org>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2021-03-04T08:59:41Z
Lists: pgsql-hackers
On 04/03/2021 01:32, Tom Lane wrote:
> Patched psql, trying to connect to a 7.3 server, reports this:
> 
> $ psql -h ...
> psql: error: connection to server at "sss2" (192.168.1.3), port 5432 failed: FATAL:  unsupported frontend protocol
> 
> $
> 
> Conversely, 7.3 psql trying to connect to a patched server reports:
> 
> $ psql -h ...
> psql: FATAL:  unsupported frontend protocol 2.0: server supports 3.0 to 3.0
> 
> $
> 
> I'm not sure where the extra newlines are coming from, and it seems
> unlikely to be worth worrying over.  This behavior is good enough for me.

fe-connect.c appends a newline for any errors in pre-3.0 format:

> 
> 		/*
> 		 * The postmaster typically won't end its message with a
> 		 * newline, so add one to conform to libpq conventions.
> 		 */
> 		appendPQExpBufferChar(&conn->errorMessage, '\n');

That comment is wrong. The postmaster *does* end all its error messages 
with a newline. This changed in commit 9b4bfbdc2c in 7.2. Before that, 
postmaster had its own function, PacketSendError(), to send error 
messages, and it did not append a newline. Commit 9b4bfbdc2 changed 
postmaster to use elog(...) like everyone else, and elog(...) has always 
appended a newline. So I think this extra newline that libpq adds is 
needed if you try to connect to PostgreSQL 7.1 or earlier. I couldn't 
commpile a 7.1 server to verify this, though.

I changed that code in libpq to check if the message already has a 
newline, and only append one if it doesn't. This fixes the extra newline 
when connecting with new libpq to a 7.3 server (and in the fork failure 
message).

> I concur that 0001 attached is committable.  I have not looked at
> your 0002, though.

Removed the entry from nls.mk, and pushed 0001. Thanks!

- Heikki



Commits

  1. Avoid extra newline in errors received in FE protocol version 2.

  2. Remove server and libpq support for old FE/BE protocol version 2.

  3. Handle reading of startup packet and authentication exchange after forking