libpq support for NegotiateProtocolVersion - Mailing list pgsql-hackers

From Peter Eisentraut
Subject libpq support for NegotiateProtocolVersion
Date
Msg-id f9c7862f-b864-8ef7-a861-c4638c83e209@enterprisedb.com
Whole thread Raw
Responses Re: libpq support for NegotiateProtocolVersion  (Nathan Bossart <nathandbossart@gmail.com>)
List pgsql-hackers
We have the NegotiateProtocolVersion protocol message [0], but libpq 
doesn't actually handle it.

Say I increase the protocol number in libpq:

-       conn->pversion = PG_PROTOCOL(3, 0);
+       conn->pversion = PG_PROTOCOL(3, 1);

Then I get

psql: error: connection to server on socket "/tmp/.s.PGSQL.65432" 
failed: expected authentication request from server, but received v

And the same for a protocol option (_pq_.something).

Over in the column encryption patch, I'm proposing to add such a 
protocol option, and the above is currently the behavior when the server 
doesn't support it.

The attached patch adds explicit handling of this protocol message to 
libpq.  So the output in the above case would then be:

psql: error: connection to server on socket "/tmp/.s.PGSQL.65432" 
failed: protocol version not supported by server: client uses 3.1, 
server supports 3.0

Or to test a protocol option:

@@ -2250,6 +2291,8 @@ build_startup_packet(const PGconn *conn, char *packet,
     if (conn->client_encoding_initial && conn->client_encoding_initial[0])
         ADD_STARTUP_OPTION("client_encoding", 
conn->client_encoding_initial);

+   ADD_STARTUP_OPTION("_pq_.foobar", "1");
+
     /* Add any environment-driven GUC settings needed */
     for (next_eo = options; next_eo->envName; next_eo++)
     {

Result:

psql: error: connection to server on socket "/tmp/.s.PGSQL.65432" 
failed: protocol extension not supported by server: _pq_.foobar


[0]: 
https://www.postgresql.org/docs/devel/protocol-message-formats.html#PROTOCOL-MESSAGE-FORMATS-NEGOTIATEPROTOCOLVERSION
Attachment

pgsql-hackers by date:

Previous
From: Richard Guo
Date:
Subject: Re: Use LIMIT instead of Unique for DISTINCT when all distinct pathkeys are redundant
Next
From: Andy Fan
Date:
Subject: Question about pull_up_sublinks_qual_recurse