From 587df6b1a81833b14cf8c2d659b21cd54a3c55f6 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <postgres@jeltef.nl>
Date: Sun, 19 Oct 2025 00:30:48 +0200
Subject: [PATCH v2 1/3] Bump protocol version to 3.3

This commit increments the PostgreSQL frontend/backend protocol version
from 3.2 to 3.3 and does the required boilerplate changes. The next
commit will introduce an actual protocol change.
---
 doc/src/sgml/libpq.sgml                       | 12 ++++++----
 doc/src/sgml/protocol.sgml                    | 22 ++++++++++++-------
 src/include/libpq/pqcomm.h                    |  2 +-
 src/interfaces/libpq/fe-connect.c             |  6 +++++
 .../modules/libpq_pipeline/libpq_pipeline.c   | 22 ++++++++++++++++---
 5 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml
index 5bf59a19855..0f43ee6b039 100644
--- a/doc/src/sgml/libpq.sgml
+++ b/doc/src/sgml/libpq.sgml
@@ -2200,10 +2200,12 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
 
        <para>
         The current supported values are
-        <literal>3.0</literal>, <literal>3.2</literal>,
+        <literal>3.0</literal>,
+        <literal>3.2</literal>,
+        <literal>3.3</literal>
         and <literal>latest</literal>. The <literal>latest</literal> value is
         equivalent to the latest protocol version supported by the libpq
-        version being used, which is currently <literal>3.2</literal>.
+        version being used, which is currently <literal>3.3</literal>.
        </para>
       </listitem>
      </varlistentry>
@@ -2226,10 +2228,12 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
 
        <para>
         The current supported values are
-        <literal>3.0</literal>, <literal>3.2</literal>,
+        <literal>3.0</literal>,
+        <literal>3.2</literal>,
+        <literal>3.3</literal>
         and <literal>latest</literal>. The <literal>latest</literal> value is
         equivalent to the latest protocol version supported by the libpq
-        version being used, which is currently <literal>3.2</literal>.
+        version being used, which is currently <literal>3.3</literal>.
        </para>
       </listitem>
      </varlistentry>
diff --git a/doc/src/sgml/protocol.sgml b/doc/src/sgml/protocol.sgml
index 9d755232873..7665bd7dcb8 100644
--- a/doc/src/sgml/protocol.sgml
+++ b/doc/src/sgml/protocol.sgml
@@ -18,8 +18,8 @@
  </para>
 
  <para>
-  This document describes version 3.2 of the protocol, introduced in
-  <productname>PostgreSQL</productname> version 18. The server and the libpq
+  This document describes version 3.3 of the protocol, introduced in
+  <productname>PostgreSQL</productname> version 19. The server and the libpq
   client library are backwards compatible with protocol version 3.0,
   implemented in <productname>PostgreSQL</productname> 7.4 and later.
  </para>
@@ -192,7 +192,7 @@
    <title>Protocol Versions</title>
 
    <para>
-    The current, latest version of the protocol is version 3.2. However, for
+    The current, latest version of the protocol is version 3.3. However, for
     backwards compatibility with old server versions and middleware that don't
     support the version negotiation yet, libpq still uses protocol version 3.0
     by default.
@@ -206,7 +206,7 @@
     this would occur if the client requested protocol version 4.0, which does
     not exist as of this writing).  If the minor version requested by the
     client is not supported by the server (e.g., the client requests version
-    3.2, but the server supports only 3.0), the server may either reject the
+    3.3, but the server supports only 3.0), the server may either reject the
     connection or may respond with a NegotiateProtocolVersion message
     containing the highest minor protocol version which it supports.  The
     client may then choose either to continue with the connection using the
@@ -238,10 +238,16 @@
      </thead>
 
      <tbody>
+      <row>
+      <entry>3.3</entry>
+      <entry>PostgreSQL 19 and later</entry>
+      <entry>Current latest version.
+      </entry>
+      </row>
       <row>
       <entry>3.2</entry>
       <entry>PostgreSQL 18 and later</entry>
-      <entry>Current latest version. The secret key used in query
+      <entry>The secret key used in query
         cancellation was enlarged from 4 bytes to a variable length field. The
         BackendKeyData message was changed to accommodate that, and the CancelRequest
         message was redefined to have a variable length payload.
@@ -6076,9 +6082,9 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
         <para>
          The protocol version number.  The most significant 16 bits are
          the major version number. The least significant 16 bits are the minor
-         version number. As an example protocol version 3.2 is represented as
-         <literal>196610</literal> in decimal or more clearly as
-         <literal>0x00030002</literal> in hexadecimal.
+         version number. As an example protocol version 3.3 is represented as
+         <literal>196611</literal> in decimal or more clearly as
+         <literal>0x00030003</literal> in hexadecimal.
         </para>
        </listitem>
       </varlistentry>
diff --git a/src/include/libpq/pqcomm.h b/src/include/libpq/pqcomm.h
index f04ca135653..2423394b348 100644
--- a/src/include/libpq/pqcomm.h
+++ b/src/include/libpq/pqcomm.h
@@ -94,7 +94,7 @@ is_unixsock_path(const char *path)
  */
 
 #define PG_PROTOCOL_EARLIEST	PG_PROTOCOL(3,0)
-#define PG_PROTOCOL_LATEST		PG_PROTOCOL(3,2)
+#define PG_PROTOCOL_LATEST		PG_PROTOCOL(3,3)
 
 typedef uint32 ProtocolVersion; /* FE/BE protocol version number */
 
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index a3d12931fff..62d35e0c789 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -8301,6 +8301,12 @@ pqParseProtocolVersion(const char *value, ProtocolVersion *result, PGconn *conn,
 		return true;
 	}
 
+	if (strcmp(value, "3.3") == 0)
+	{
+		*result = PG_PROTOCOL(3, 3);
+		return true;
+	}
+
 	libpq_append_conn_error(conn, "invalid %s value: \"%s\"",
 							context, value);
 	return false;
diff --git a/src/test/modules/libpq_pipeline/libpq_pipeline.c b/src/test/modules/libpq_pipeline/libpq_pipeline.c
index b3af70fa09b..0b113b271ea 100644
--- a/src/test/modules/libpq_pipeline/libpq_pipeline.c
+++ b/src/test/modules/libpq_pipeline/libpq_pipeline.c
@@ -1405,7 +1405,23 @@ test_protocol_version(PGconn *conn)
 	PQfinish(conn);
 
 	/*
-	 * Test max_protocol_version=latest. 'latest' currently means '3.2'.
+	 * Test max_protocol_version=3.3
+	 */
+	vals[max_protocol_version_index] = "3.3";
+	conn = PQconnectdbParams(keywords, vals, false);
+
+	if (PQstatus(conn) != CONNECTION_OK)
+		pg_fatal("Connection to database failed: %s",
+				 PQerrorMessage(conn));
+
+	protocol_version = PQfullProtocolVersion(conn);
+	if (protocol_version != 30003)
+		pg_fatal("expected 30003, got %d", protocol_version);
+
+	PQfinish(conn);
+
+	/*
+	 * Test max_protocol_version=latest. 'latest' currently means '3.3'.
 	 */
 	vals[max_protocol_version_index] = "latest";
 	conn = PQconnectdbParams(keywords, vals, false);
@@ -1415,8 +1431,8 @@ test_protocol_version(PGconn *conn)
 				 PQerrorMessage(conn));
 
 	protocol_version = PQfullProtocolVersion(conn);
-	if (protocol_version != 30002)
-		pg_fatal("expected 30002, got %d", protocol_version);
+	if (protocol_version != 30003)
+		pg_fatal("expected 30003, got %d", protocol_version);
 
 	PQfinish(conn);
 
-- 
2.51.1

