public inbox for [email protected]
help / color / mirror / Atom feedFrom: Jacob Champion <[email protected]>
To: Tom Lane <[email protected]>
Cc: Jelte Fennema-Nio <[email protected]>
Cc: [email protected]
Cc: Andrew Dunstan <[email protected]>
Subject: Re: pgsql: libpq: Grease the protocol by default
Date: Mon, 23 Feb 2026 15:41:46 -0800
Message-ID: <CAOYmi+mtFBsB2zePSvbpa-2Zb-+V5bov_t2BzkGH7vfKX0ny_w@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<CAOYmi+=4QhCjssfNEoZVK8LPtWxnfkwT5p-PAeoxtG9gpNjqOQ@mail.gmail.com>
<[email protected]>
<CAOYmi+k8ENYkErqSEYEqW39YWPfe_ii7g5Acm1c9asNuRMriNg@mail.gmail.com>
<[email protected]>
On Mon, Feb 23, 2026 at 3:34 PM Tom Lane <[email protected]> wrote:
> > So a fix belongs in pg_upgrade, IMO, instead of the test. I have a
> > draft passing locally that I should be able to share soon.
>
> Fair enough.
Something like the attached (tested only against 9.2 so far)? I would
plan to backpatch after feature freeze is lifted.
--Jacob
Attachments:
[application/octet-stream] 0001-pg_upgrade-Use-max_protocol_version-3.0-for-older-se.patch (4.8K, 2-0001-pg_upgrade-Use-max_protocol_version-3.0-for-older-se.patch)
download | inline diff:
From 5256bf5af7addef6fce9f4c1a8aa9604a4aea7f4 Mon Sep 17 00:00:00 2001
From: Jacob Champion <[email protected]>
Date: Mon, 23 Feb 2026 15:28:32 -0800
Subject: [PATCH] pg_upgrade: Use max_protocol_version=3.0 for older servers
The grease patch in 4966bd3ed found its first problem: prior to the
February 2018 patch releases, no server knew how to negotiate protocol
versions, so pg_upgrade needs to take that into account when speaking to
those versions.
This will be true even after the grease feature is reverted; we don't
need anyone to trip over this again in the future. Backpatch so that all
supported versions of pg_upgrade can gracefully handle an update to the
default protocol version in newer libpqs.
Per buildfarm member crake.
Discussion: https://postgr.es/m/CAOYmi%2B%3D4QhCjssfNEoZVK8LPtWxnfkwT5p-PAeoxtG9gpNjqOQ%40mail.gmail.com
Backpatch-through: 14
---
src/bin/pg_upgrade/pg_upgrade.h | 1 +
src/bin/pg_upgrade/dump.c | 6 +++++-
src/bin/pg_upgrade/server.c | 2 ++
src/bin/pg_upgrade/task.c | 2 ++
src/bin/pg_upgrade/version.c | 24 ++++++++++++++++++++++++
5 files changed, 34 insertions(+), 1 deletion(-)
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index ec018e4f292..1d767bbda2d 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -501,6 +501,7 @@ unsigned int str2uint(const char *str);
/* version.c */
bool jsonb_9_4_check_applicable(ClusterInfo *cluster);
+bool protocol_negotiation_supported(const ClusterInfo *cluster);
void old_9_6_invalidate_hash_indexes(ClusterInfo *cluster,
bool check_mode);
diff --git a/src/bin/pg_upgrade/dump.c b/src/bin/pg_upgrade/dump.c
index e4c9349311a..f47c8d06211 100644
--- a/src/bin/pg_upgrade/dump.c
+++ b/src/bin/pg_upgrade/dump.c
@@ -21,9 +21,10 @@ generate_old_dump(void)
/* run new pg_dumpall binary for globals */
exec_prog(UTILITY_LOG_FILE, NULL, true, true,
- "\"%s/pg_dumpall\" %s --globals-only --quote-all-identifiers "
+ "\"%s/pg_dumpall\" %s%s --globals-only --quote-all-identifiers "
"--binary-upgrade %s --no-sync -f \"%s/%s\"",
new_cluster.bindir, cluster_conn_opts(&old_cluster),
+ protocol_negotiation_supported(&old_cluster) ? "" : " -d \"max_protocol_version=3.0\"",
log_opts.verbose ? "--verbose" : "",
log_opts.dumpdir,
GLOBALS_DUMP_FILE);
@@ -43,6 +44,9 @@ generate_old_dump(void)
initPQExpBuffer(&connstr);
appendPQExpBufferStr(&connstr, "dbname=");
appendConnStrVal(&connstr, old_db->db_name);
+ if (!protocol_negotiation_supported(&old_cluster))
+ appendPQExpBufferStr(&connstr, " max_protocol_version=3.0");
+
initPQExpBuffer(&escaped_connstr);
appendShellString(&escaped_connstr, connstr.data);
termPQExpBuffer(&connstr);
diff --git a/src/bin/pg_upgrade/server.c b/src/bin/pg_upgrade/server.c
index eeeac3153f0..1eb8bc97c05 100644
--- a/src/bin/pg_upgrade/server.c
+++ b/src/bin/pg_upgrade/server.c
@@ -71,6 +71,8 @@ get_db_conn(ClusterInfo *cluster, const char *db_name)
appendPQExpBufferStr(&conn_opts, " host=");
appendConnStrVal(&conn_opts, cluster->sockdir);
}
+ if (!protocol_negotiation_supported(cluster))
+ appendPQExpBufferStr(&conn_opts, " max_protocol_version=3.0");
conn = PQconnectdb(conn_opts.data);
termPQExpBuffer(&conn_opts);
diff --git a/src/bin/pg_upgrade/task.c b/src/bin/pg_upgrade/task.c
index d4cd487bad0..3d958527528 100644
--- a/src/bin/pg_upgrade/task.c
+++ b/src/bin/pg_upgrade/task.c
@@ -188,6 +188,8 @@ start_conn(const ClusterInfo *cluster, UpgradeTaskSlot *slot)
appendPQExpBufferStr(&conn_opts, " host=");
appendConnStrVal(&conn_opts, cluster->sockdir);
}
+ if (!protocol_negotiation_supported(cluster))
+ appendPQExpBufferStr(&conn_opts, " max_protocol_version=3.0");
slot->conn = PQconnectStart(conn_opts.data);
diff --git a/src/bin/pg_upgrade/version.c b/src/bin/pg_upgrade/version.c
index e709262837e..7e1eff0c972 100644
--- a/src/bin/pg_upgrade/version.c
+++ b/src/bin/pg_upgrade/version.c
@@ -28,6 +28,30 @@ jsonb_9_4_check_applicable(ClusterInfo *cluster)
return false;
}
+/*
+ * Older servers can't support newer protocol versions, so their connection
+ * strings will need to lock max_protocol_version to 3.0.
+ */
+bool
+protocol_negotiation_supported(const ClusterInfo *cluster)
+{
+ int major = GET_MAJOR_VERSION(cluster->major_version);
+
+ /*
+ * These version numbers come from the February 2018 patch release, which
+ * added support for NegotiateProtocolVersion: 9.3.21, 9.4.16, 9.5.11,
+ * 9.6.7, and 10.2.
+ */
+ if (cluster->major_version < 90321
+ || (major == 904 && cluster->major_version < 90416)
+ || (major == 905 && cluster->major_version < 90511)
+ || (major == 906 && cluster->major_version < 90607)
+ || (major == 1000 && cluster->major_version < 100002))
+ return false;
+
+ return true;
+}
+
/*
* old_9_6_invalidate_hash_indexes()
* 9.6 -> 10
--
2.34.1
view thread (27+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: pgsql: libpq: Grease the protocol by default
In-Reply-To: <CAOYmi+mtFBsB2zePSvbpa-2Zb-+V5bov_t2BzkGH7vfKX0ny_w@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox