[PATCH] Reserve protocol 3.1 explicitly in pqcomm.h
Hi,
This is a tiny followup to https://postgr.es/c/0664aa4ff8 that
enshrines the unused 3.1 protocol version as PG_PROTOCOL_RSRV31. The
patch comes from [1]/messages/by-id/CAOYmi+=PMq5wiKjBuOF2_W6JYRnPFYbgp7P-MRa2ymFo89=6BQ@mail.gmail.com; I just wanted to give people the opportunity to
bikeshed the name (or object to the move?) before it becomes part of a
public header.
Thanks,
--Jacob
[1]: /messages/by-id/CAOYmi+=PMq5wiKjBuOF2_W6JYRnPFYbgp7P-MRa2ymFo89=6BQ@mail.gmail.com
Attachments:
0001-pqcomm.h-Explicitly-reserve-protocol-v3.1.patchapplication/octet-stream; name=0001-pqcomm.h-Explicitly-reserve-protocol-v3.1.patchDownload
From 4ed03c6a73361b01610373267a843cbef110946d Mon Sep 17 00:00:00 2001
From: Jacob Champion <jacob.champion@enterprisedb.com>
Date: Fri, 21 Nov 2025 09:18:40 -0800
Subject: [PATCH] pqcomm.h: Explicitly reserve protocol v3.1
Document this unused version alongside the other special protocol
numbers.
Reviewed-by: Jelte Fennema-Nio <postgres@jeltef.nl>
---
src/include/libpq/pqcomm.h | 6 ++++++
src/interfaces/libpq/fe-protocol3.c | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/include/libpq/pqcomm.h b/src/include/libpq/pqcomm.h
index 6df6e0f902d..2e24083f462 100644
--- a/src/include/libpq/pqcomm.h
+++ b/src/include/libpq/pqcomm.h
@@ -98,6 +98,12 @@ is_unixsock_path(const char *path)
* Reserved protocol numbers, which have special semantics:
*/
+/*
+ * 3.1 would have collided with old pgbouncer deployments, and was skipped. We
+ * neither emit it nor accept it on the wire.
+ */
+#define PG_PROTOCOL_RSRV31 PG_PROTOCOL(3,1)
+
/*
* A client can send a cancel-current-operation request to the postmaster.
* This is uglier than sending it directly to the client's backend, but it
diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c
index 34518bbe6ea..2d67c496a3d 100644
--- a/src/interfaces/libpq/fe-protocol3.c
+++ b/src/interfaces/libpq/fe-protocol3.c
@@ -1465,7 +1465,7 @@ pqGetNegotiateProtocolVersion3(PGconn *conn)
}
/* 3.1 never existed, we went straight from 3.0 to 3.2 */
- if (their_version == PG_PROTOCOL(3, 1))
+ if (their_version == PG_PROTOCOL_RSRV31)
{
libpq_append_conn_error(conn, "received invalid protocol negotiation message: server requested downgrade to non-existent 3.1 protocol version");
goto failure;
--
2.34.1
Jacob Champion <jacob.champion@enterprisedb.com> writes:
This is a tiny followup to https://postgr.es/c/0664aa4ff8 that
enshrines the unused 3.1 protocol version as PG_PROTOCOL_RSRV31. The
patch comes from [1]; I just wanted to give people the opportunity to
bikeshed the name (or object to the move?) before it becomes part of a
public header.
+1 for concept, but I agree the name needs bikeshedding. "RSRV"
is unreadable, and people might well mentally expand it to
something involving "server", leading to confusion.
How about "PG_PROTOCOL_RESERVED_31" or
"PG_PROTOCOL_UNUSED_31"?
regards, tom lane
On Tue, Jan 20, 2026 at 3:10 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
How about "PG_PROTOCOL_RESERVED_31" or
"PG_PROTOCOL_UNUSED_31"?
I'd be fine with either; slight preference for "RESERVED" I suppose?
Thanks!
--Jacob
On Wed Jan 21, 2026 at 12:17 AM CET, Jacob Champion wrote:
I'd be fine with either; slight preference for "RESERVED" I suppose?
RESERVED seems clearer to me. And for people interested in why, the
comment above its definition describes it suffiecently.
On Tue, Jan 20, 2026 at 11:50 PM Jelte Fennema-Nio <postgres@jeltef.nl> wrote:
RESERVED seems clearer to me. And for people interested in why, the
comment above its definition describes it suffiecently.
Pushed as PG_PROTOCOL_RESERVED_31. Thank you both!
--Jacob