v4-0005-pqcomm.h-Explicitly-reserve-protocol-v3.1.patch

application/octet-stream

Filename: v4-0005-pqcomm.h-Explicitly-reserve-protocol-v3.1.patch
Type: application/octet-stream
Part: 4
Message: Re: libpq: Bump protocol version to version 3.2 at least until the first/second beta

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v4-0005
Subject: pqcomm.h: Explicitly reserve protocol v3.1
File+
src/include/libpq/pqcomm.h 6 0
src/interfaces/libpq/fe-protocol3.c 1 1
From edd5d0719c3095a1dbbcefc0ef4c8b2b37d4a2d8 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 v4 5/5] pqcomm.h: Explicitly reserve protocol v3.1

Document this alongside the other special protocol numbers.
---
 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 0fe7d8e897d..31577e1cf98 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)
+
 /*
  * PG_PROTOCOL_GREASE is an intentionally unsupported protocol version used
  * for GREASE (Generate Random Extensions And Sustain Extensibility). This
diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c
index 7457ba2498c..e32a7a33e32 100644
--- a/src/interfaces/libpq/fe-protocol3.c
+++ b/src/interfaces/libpq/fe-protocol3.c
@@ -1467,7 +1467,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