pgsql: libpq: Add min/max_protocol_version connection options

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: libpq: Add min/max_protocol_version connection options
Date: 2025-04-02 13:43:17
Message-ID: E1tzyNB-002IXY-0e@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

libpq: Add min/max_protocol_version connection options

All supported version of the PostgreSQL server send the
NegotiateProtocolVersion message when an unsupported minor protocol
version is requested by a client. But many other applications that
implement the PostgreSQL protocol (connection poolers, or other
databases) do not, and the same is true for PostgreSQL server versions
older than 9.3. Connecting to such other applications thus fails if a
client requests a protocol version different than 3.0.

This patch adds a max_protocol_version connection option to libpq that
specifies the protocol version that libpq should request from the
server. Currently only 3.0 is supported, but that will change in a
future commit that bumps the protocol version. Even after that version
bump the default will likely stay 3.0 for the time being. Once more of
the ecosystem supports the NegotiateProtocolVersion message we might
want to change the default to the latest minor version.

This also adds the similar min_protocol_version connection option, to
allow the client to specify that connecting should fail if a lower
protocol version is attempted by the server. This can be used to
ensure that certain protocol features are used, which can be
particularly useful if those features impact security.

Author: Jelte Fennema-Nio <postgres(at)jeltef(dot)nl>
Reviewed-by: Robert Haas <robertmhaas(at)gmail(dot)com> (earlier versions)
Discussion: https://www.postgresql.org/message-id/CAGECzQTfc_O%2BHXqAo5_-xG4r3EFVsTefUeQzSvhEyyLDba-O9w@mail.gmail.com
Discussion: https://www.postgresql.org/message-id/CAGECzQRbAGqJnnJJxTdKewTsNOovUt4bsx3NFfofz3m2j-t7tA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/285613c60a7aff5daaf281c67002483b0d26e715

Modified Files
--------------
doc/src/sgml/libpq.sgml | 68 ++++++++++++++
doc/src/sgml/protocol.sgml | 33 +++++--
src/include/libpq/pqcomm.h | 3 +-
src/interfaces/libpq/fe-connect.c | 88 +++++++++++++++++-
src/interfaces/libpq/fe-protocol3.c | 18 ++++
src/interfaces/libpq/libpq-int.h | 4 +
src/test/modules/libpq_pipeline/libpq_pipeline.c | 113 ++++++++++++++++++++++-
7 files changed, 315 insertions(+), 12 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2025-04-02 15:13:18 pgsql: Need to do CommandCounterIncrement after StoreAttrMissingVal.
Previous Message Peter Eisentraut 2025-04-02 12:47:19 pgsql: Fix code comment