Re: Correct documentation for protocol version

From: Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com>
To: Dave Cramer <davecramer(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Correct documentation for protocol version
Date: 2025-04-10 15:17:51
Message-ID: 0bfdd320-92e8-48a1-a1be-82c24918630c@oss.nttdata.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2025/04/10 23:40, Dave Cramer wrote:
>
> On Thu, 10 Apr 2025 at 09:54, Fujii Masao <masao(dot)fujii(at)oss(dot)nttdata(dot)com <mailto:masao(dot)fujii(at)oss(dot)nttdata(dot)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.

> +         Major is in the upper 16 bits and the lower in the low 16 bits.
>
> To match the style of similar descriptions, how about rephrasing it as:
> "The most significant 16 bits are the major version number, and the least
> significant 16 bits are the minor version number”?
>
> Done in new patch attached

Thanks!

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Adrian Klaver 2025-04-10 15:22:56 Re: Capturing both IP address and hostname in the log
Previous Message Jacob Champion 2025-04-10 15:14:55 Re: Correct documentation for protocol version