Re: Correct documentation for protocol version - Mailing list pgsql-hackers

From Dave Cramer
Subject Re: Correct documentation for protocol version
Date
Msg-id CADK3HHLLU21LgvPMR0b2CR85ME+WukmG3w=p9JVv0ahv562mnA@mail.gmail.com
Whole thread Raw
In response to Re: Correct documentation for protocol version  (Fujii Masao <masao.fujii@oss.nttdata.com>)
Responses Re: Correct documentation for protocol version
List pgsql-hackers


On Thu, 10 Apr 2025 at 11:17, Fujii Masao <masao.fujii@oss.nttdata.com> wrote:


On 2025/04/10 23:40, Dave Cramer wrote:
>
> On Thu, 10 Apr 2025 at 09:54, Fujii Masao <masao.fujii@oss.nttdata.com <mailto:masao.fujii@oss.nttdata.com>> wrote:
>
>
>
>     On 2025/04/10 18:52, Dave Cramer wrote:
>      > Greetings,
>      >
>      > The current docs say that if a client asks for a protocol that the backend doesn't support, it will return the newest minor version. https://www.postgresql.org/docs/current/protocol-message-formats.html#PROTOCOL-MESSAGE-FORMATS-NEGOTIATEPROTOCOLVERSION <https://www.postgresql.org/docs/current/protocol-message-formats.html#PROTOCOL-MESSAGE-FORMATS-NEGOTIATEPROTOCOLVERSION> <https://www.postgresql.org/docs/current/protocol-message-formats.html#PROTOCOL-MESSAGE-FORMATS-NEGOTIATEPROTOCOLVERSION <https://www.postgresql.org/docs/current/protocol-message-formats.html#PROTOCOL-MESSAGE-FORMATS-NEGOTIATEPROTOCOLVERSION>>
>      >
>      > However that isn't what it returns. It actually returns the entire newest protocol that it supports. Attached is a patch to fix the docs.
>
>     As far as I read the code, the server returns the protocol version requested by
>     the client if it's less than or equal to the latest version the server supports.
>     Otherwise, it returns the latest supported version. So the proposed description
>     doesn't seem accurate either, does it?
>
> I've added a note as to when this is sent. AFAICT through testing and the fact that the pgjdbc driver has never handled this message
> I'm pretty sure it only sends this message if the requested protocol is not equal to the protocol the server supports.

No, the message is also sent when the client requests protocol options that
the server doesn't recognize. In that case, if the client requests an older
protocol version along with unknown options, the server responds with
the requested protocol version, not the latest one.

OK, I hadn't contemplated the unrecognized options. However AFAICT the documentation in the code state

/*
* If the client requested a newer protocol version or if the client
* requested any protocol options we didn't recognize, let them know
* the newest minor protocol version we do support and the names of
* any unrecognized options.
*/

and the code agrees that we send the latest protocol version that we support, not the requested one.

Dave
Attachment

pgsql-hackers by date:

Previous
From: Xuneng Zhou
Date:
Subject: Re: Proposal: Limitations of palloc inside checkpointer
Next
From: Tom Lane
Date:
Subject: Re: Capturing both IP address and hostname in the log