public inbox for [email protected]
help / color / mirror / Atom feedpgsql: libpq: Grease the protocol by default
27+ messages / 7 participants
[nested] [flat]
* pgsql: libpq: Grease the protocol by default
@ 2026-02-23 18:58 Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
0 siblings, 1 reply; 27+ messages in thread
From: Jacob Champion @ 2026-02-23 18:58 UTC (permalink / raw)
To: [email protected]
libpq: Grease the protocol by default
Send PG_PROTOCOL_GREASE and _pq_.test_protocol_negotiation, which were
introduced in commit d8d7c5dc8, by default, and fail the connection if
the server attempts to claim support for them. The hope is to provide
feedback to noncompliant implementations and gain confidence in our
ability to advance the protocol. (See the other commit for details.)
To help end users navigate the situation, a link to our documentation
that explains the behavior is displayed. We append this to the error
message when the NegotiateProtocolVersion response is incorrect, or when
the peer sends an error during startup that appears to be grease-
related.
It's still possible for users to connect to servers that don't support
protocol negotiation, by adding max_protocol_version=3.0 to their
connection strings. Only the default connection behavior is impacted.
This commit is tracked as a PG19 open item and will be reverted before
RC1. (The implementation here doesn't handle negotiation with later
server versions, so it can't be released into the wild as a
five-year-supported feature. But an improved implementation might be
able to do so, in the future...)
Author: Jelte Fennema-Nio <[email protected]>
Co-authored-by: Jacob Champion <[email protected]>
Discussion: https://postgr.es/m/DDPR5BPWH1RJ.1LWAK6QAURVAY%40jeltef.nl
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/4966bd3ed95e0d02bf220c4bad2b292963827dd4
Modified Files
--------------
doc/src/sgml/libpq.sgml | 17 ++++++++
doc/src/sgml/protocol.sgml | 11 +++++
src/interfaces/libpq/fe-connect.c | 51 +++++++++++++++++++-----
src/interfaces/libpq/fe-misc.c | 18 +++++++++
src/interfaces/libpq/fe-protocol3.c | 51 ++++++++++++++++++++++--
src/interfaces/libpq/libpq-int.h | 1 +
src/test/modules/libpq_pipeline/libpq_pipeline.c | 6 +--
7 files changed, 140 insertions(+), 15 deletions(-)
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
@ 2026-02-23 21:17 ` Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:24 ` Re: pgsql: libpq: Grease the protocol by default Jelte Fennema-Nio <[email protected]>
0 siblings, 2 replies; 27+ messages in thread
From: Jacob Champion @ 2026-02-23 21:17 UTC (permalink / raw)
To: Jacob Champion <[email protected]>; +Cc: [email protected]; Jelte Fennema-Nio <[email protected]>
On Mon, Feb 23, 2026 at 10:58 AM Jacob Champion
<[email protected]> wrote:
>
> libpq: Grease the protocol by default
crake is angry:
> pg_dumpall: error: connection to server on socket "/home/andrew/bf/root/tmp/buildfarm-onigY7/.s.PGSQL.5670" failed: FATAL: unsupported frontend protocol 3.9999: server supports 1.0 to 3.0
> This indicates a bug in either the server being contacted
> or a proxy handling the connection. Please consider
> ...
So while this is kind of a nice result, in that it's correctly
diagnosing the problem, I need to add max_protocol_version=3.0 to the
connection strings for these upgrades during beta.
--Jacob
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
@ 2026-02-23 22:18 ` Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
1 sibling, 1 reply; 27+ messages in thread
From: Tom Lane @ 2026-02-23 22:18 UTC (permalink / raw)
To: Jacob Champion <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>
[ moving discussion to -hackers ]
Jacob Champion <[email protected]> writes:
> crake is angry:
>> pg_dumpall: error: connection to server on socket "/home/andrew/bf/root/tmp/buildfarm-onigY7/.s.PGSQL.5670" failed: FATAL: unsupported frontend protocol 3.9999: server supports 1.0 to 3.0
>> This indicates a bug in either the server being contacted
>> or a proxy handling the connection. Please consider
>> ...
> So while this is kind of a nice result, in that it's correctly
> diagnosing the problem, I need to add max_protocol_version=3.0 to the
> connection strings for these upgrades during beta.
Either that or we decide that it's time to throw 9.2 support
overboard (looks like 9.3 and up are fine).
If it's not hard to add the connection option to this test, let's do
that --- but if it is a problem, I wouldn't shed too many tears over
moving the oldest-old-version goalpost. I think we might not be able
to fix the test without changing buildfarm client script and/or
configuration.
regards, tom lane
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
@ 2026-02-23 22:51 ` Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
0 siblings, 1 reply; 27+ messages in thread
From: Jacob Champion @ 2026-02-23 22:51 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>
On Mon, Feb 23, 2026 at 2:18 PM Tom Lane <[email protected]> wrote:
> Either that or we decide that it's time to throw 9.2 support
> overboard (looks like 9.3 and up are fine).
Well, while I was hacking on a patch I realized that 9.3 (all the way
up to 10) is only okay if you're running a sufficiently patched
version. PG11 is the first to support negotiation for the whole
release line.
> If it's not hard to add the connection option to this test, let's do
> that --- but if it is a problem, I wouldn't shed too many tears over
> moving the oldest-old-version goalpost. I think we might not be able
> to fix the test without changing buildfarm client script and/or
> configuration.
I think Jelte said it well back on the -committers thread:
> Why only force max_protocol_version=3.0 for beta? It sounds like
> this would also be an issue once we eventually bump the default
> version.
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.
Thanks,
--Jacob
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
@ 2026-02-23 23:34 ` Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 16:17 ` Re: pgsql: libpq: Grease the protocol by default Nathan Bossart <[email protected]>
0 siblings, 2 replies; 27+ messages in thread
From: Tom Lane @ 2026-02-23 23:34 UTC (permalink / raw)
To: Jacob Champion <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>
Jacob Champion <[email protected]> writes:
> On Mon, Feb 23, 2026 at 2:18 PM Tom Lane <[email protected]> wrote:
>> Either that or we decide that it's time to throw 9.2 support
>> overboard (looks like 9.3 and up are fine).
> Well, while I was hacking on a patch I realized that 9.3 (all the way
> up to 10) is only okay if you're running a sufficiently patched
> version. PG11 is the first to support negotiation for the whole
> release line.
Hmm ... and of course the whole point of this exercise is to be sure
we can pg_upgrade from those out-of-support versions.
> I think Jelte said it well back on the -committers thread:
>> Why only force max_protocol_version=3.0 for beta? It sounds like
>> this would also be an issue once we eventually bump the default
>> version.
> 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.
regards, tom lane
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
@ 2026-02-23 23:41 ` Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
1 sibling, 1 reply; 27+ messages in thread
From: Jacob Champion @ 2026-02-23 23:41 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[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
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
@ 2026-02-24 00:45 ` Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 01:17 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
0 siblings, 2 replies; 27+ messages in thread
From: Tom Lane @ 2026-02-24 00:45 UTC (permalink / raw)
To: Jacob Champion <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>
Jacob Champion <[email protected]> writes:
> Something like the attached (tested only against 9.2 so far)? I would
> plan to backpatch after feature freeze is lifted.
This does not fix it for me on a local buildfarm instance. I still get
the same failure during 9.2-to-HEAD cross-version upgrade:
==~_~===-=-===~_~== /home/buildfarm/bf-data/fs-upgrade.tester/HEAD/REL9_2_STABLE-dump1.log ==~_~===-=-===~_~==
pg_dumpall: error: connection to server on socket "/home/buildfarm/bf-data/tmp/buildfarm-0fIcMg/.s.PGSQL.5700" failed: FATAL: unsupported frontend protocol 3.9999: server supports 1.0 to 3.0
This indicates a bug in either the server being contacted
or a proxy handling the connection. Please consider
reporting this to the maintainers of that software.
For more information, including instructions on how to
work around this issue for now, visit
https://www.postgresql.org/docs/devel/libpq-connect.html#LIBPQ-CONNECT-MAX-PROTOCOL-VERSION
It's not obvious to me where the problem lies. I can replicate
the failure by trying to use HEAD's psql to connect to a 9.2
server, but adding -d "max_protocol_version=3.0" makes psql happy,
so why not pg_dumpall?
Also: I was initially baffled why you thought this needs
back-patching, but I guess you have one eye on packagers like
Debian who think they can make older versions use newer libpq.so.
It'd be good to spell out that reasoning in the commit message.
regards, tom lane
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
@ 2026-02-24 01:05 ` Jacob Champion <[email protected]>
2026-02-24 02:08 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
1 sibling, 1 reply; 27+ messages in thread
From: Jacob Champion @ 2026-02-24 01:05 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>
On Mon, Feb 23, 2026 at 4:45 PM Tom Lane <[email protected]> wrote:
> Jacob Champion <[email protected]> writes:
> > Something like the attached (tested only against 9.2 so far)? I would
> > plan to backpatch after feature freeze is lifted.
(er, should have been "release freeze", though we're clearly in no hurry)
> Also: I was initially baffled why you thought this needs
> back-patching, but I guess you have one eye on packagers like
> Debian who think they can make older versions use newer libpq.so.
Right.
> It'd be good to spell out that reasoning in the commit message.
Okay, will do.
> It's not obvious to me where the problem lies. I can replicate
> the failure by trying to use HEAD's psql to connect to a 9.2
> server, but adding -d "max_protocol_version=3.0" makes psql happy,
> so why not pg_dumpall?
Hmmm, looks like the -dump1.log output is actually from *before*
pg_upgrade actually runs:
https://github.com/PGBuildFarm/client-code/blob/28d7e945cc2a27fecdf4cc685782821ca504db5d/PGBuild/Mod...
So that will still need to be modified in the buildfarm client,
independently of my patch. (I reproduced the error with a bare
pg_upgrade invocation and didn't think to look closer; sorry for the
confusion.)
--Jacob
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
@ 2026-02-24 02:08 ` Tom Lane <[email protected]>
2026-02-24 15:55 ` Re: pgsql: libpq: Grease the protocol by default Andrew Dunstan <[email protected]>
2026-02-24 17:18 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
0 siblings, 2 replies; 27+ messages in thread
From: Tom Lane @ 2026-02-24 02:08 UTC (permalink / raw)
To: Jacob Champion <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>
Jacob Champion <[email protected]> writes:
> On Mon, Feb 23, 2026 at 4:45 PM Tom Lane <[email protected]> wrote:
>> Also: I was initially baffled why you thought this needs
>> back-patching, but I guess you have one eye on packagers like
>> Debian who think they can make older versions use newer libpq.so.
> Right.
Actually, that is going to be harder than you thought, because libpq
before v18 will spit up on connection option "max_protocol_version".
This patch will not work as-is for back-patching unless we care to
also back-patch the addition of that option, which I'd be inclined
to resist.
Fortunately, we long ago had the foresight to invent PQlibVersion,
so you could make addition of the extra option conditional on
PQlibVersion(conn) >= 180000 in branches before 18.
> Hmmm, looks like the -dump1.log output is actually from *before*
> pg_upgrade actually runs:
Yeah, I came to the same conclusion. I got a clean BF run using
your patch together with the attached patch for the BF client.
(In this patch, I did not worry about scenarios involving old
minor releases. If Andrew is excited about that case he can
extend the version-comparison logic.)
regards, tom lane
Attachments:
[text/x-diff] cross-version.patch (931B, 2-cross-version.patch)
download | inline diff:
--- PGBuild/Modules/TestUpgradeXversion.pm~ 2025-11-25 07:47:25.000000000 -0500
+++ PGBuild/Modules/TestUpgradeXversion.pm 2026-02-23 20:57:31.640149574 -0500
@@ -483,9 +483,17 @@ sub test_upgrade ## no critic (Subrou
$dump_opts .= ' --extra-float-digits=0';
}
+ # with very old servers we must restrict the protocol version.
+ my $maxpversion = "";
+ if ( ($this_branch eq 'HEAD' || $this_branch gt 'REL_18_STABLE')
+ && ($oversion ne 'HEAD' && $oversion le 'REL_9_2_STABLE'))
+ {
+ $maxpversion = '-d max_protocol_version=3.0';
+ }
+
# use the NEW pg_dumpall so we're comparing apples with apples.
setinstenv($self, "$installdir", $save_env);
- system( qq{"$installdir/bin/pg_dumpall" $dump_opts -p $sport -f }
+ system( qq{"$installdir/bin/pg_dumpall" $dump_opts $maxpversion -p $sport -f }
. qq{"$upgrade_loc/origin-$oversion.sql" }
. qq{> "$upgrade_loc/$oversion-dump1.log" 2>&1});
return if $?;
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 02:08 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
@ 2026-02-24 15:55 ` Andrew Dunstan <[email protected]>
2026-02-24 22:49 ` Re: pgsql: libpq: Grease the protocol by default Andrew Dunstan <[email protected]>
1 sibling, 1 reply; 27+ messages in thread
From: Andrew Dunstan @ 2026-02-24 15:55 UTC (permalink / raw)
To: Tom Lane <[email protected]>; Jacob Champion <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]
On 2026-02-23 Mo 9:08 PM, Tom Lane wrote:
> Jacob Champion<[email protected]> writes:
>> On Mon, Feb 23, 2026 at 4:45 PM Tom Lane<[email protected]> wrote:
>>> Also: I was initially baffled why you thought this needs
>>> back-patching, but I guess you have one eye on packagers like
>>> Debian who think they can make older versions use newer libpq.so.
>> Right.
> Actually, that is going to be harder than you thought, because libpq
> before v18 will spit up on connection option "max_protocol_version".
> This patch will not work as-is for back-patching unless we care to
> also back-patch the addition of that option, which I'd be inclined
> to resist.
>
> Fortunately, we long ago had the foresight to invent PQlibVersion,
> so you could make addition of the extra option conditional on
> PQlibVersion(conn) >= 180000 in branches before 18.
>
>> Hmmm, looks like the -dump1.log output is actually from *before*
>> pg_upgrade actually runs:
> Yeah, I came to the same conclusion. I got a clean BF run using
> your patch together with the attached patch for the BF client.
> (In this patch, I did not worry about scenarios involving old
> minor releases. If Andrew is excited about that case he can
> extend the version-comparison logic.)
>
>
I am not worried about old minor releases. I am currently testing a
patch with similar intent to yours.
cheers
andrew
--
Andrew Dunstan
EDB:https://www.enterprisedb.com
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 02:08 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 15:55 ` Re: pgsql: libpq: Grease the protocol by default Andrew Dunstan <[email protected]>
@ 2026-02-24 22:49 ` Andrew Dunstan <[email protected]>
2026-02-24 22:59 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
0 siblings, 1 reply; 27+ messages in thread
From: Andrew Dunstan @ 2026-02-24 22:49 UTC (permalink / raw)
To: Tom Lane <[email protected]>; Jacob Champion <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]
On 2026-02-24 Tu 10:55 AM, Andrew Dunstan wrote:
>
>
> On 2026-02-23 Mo 9:08 PM, Tom Lane wrote:
>> Jacob Champion<[email protected]> writes:
>>> On Mon, Feb 23, 2026 at 4:45 PM Tom Lane<[email protected]> wrote:
>>>> Also: I was initially baffled why you thought this needs
>>>> back-patching, but I guess you have one eye on packagers like
>>>> Debian who think they can make older versions use newer libpq.so.
>>> Right.
>> Actually, that is going to be harder than you thought, because libpq
>> before v18 will spit up on connection option "max_protocol_version".
>> This patch will not work as-is for back-patching unless we care to
>> also back-patch the addition of that option, which I'd be inclined
>> to resist.
>>
>> Fortunately, we long ago had the foresight to invent PQlibVersion,
>> so you could make addition of the extra option conditional on
>> PQlibVersion(conn) >= 180000 in branches before 18.
>>
>>> Hmmm, looks like the -dump1.log output is actually from *before*
>>> pg_upgrade actually runs:
>> Yeah, I came to the same conclusion. I got a clean BF run using
>> your patch together with the attached patch for the BF client.
>> (In this patch, I did not worry about scenarios involving old
>> minor releases. If Andrew is excited about that case he can
>> extend the version-comparison logic.)
>>
>>
>
>
> I am not worried about old minor releases. I am currently testing a
> patch with similar intent to yours.
>
>
Here's what worked for me, even before Jacob's patch of 15 minutes or so
ago.
cheers
andrew
--
Andrew Dunstan
EDB: https://www.enterprisedb.com
Attachments:
[text/x-patch] maxprotocolversion.patch (970B, 2-maxprotocolversion.patch)
download | inline diff:
diff --git a/PGBuild/Modules/TestUpgradeXversion.pm b/PGBuild/Modules/TestUpgradeXversion.pm
index a5e6be5..8e8d262 100644
--- a/PGBuild/Modules/TestUpgradeXversion.pm
+++ b/PGBuild/Modules/TestUpgradeXversion.pm
@@ -513,6 +513,9 @@ sub test_upgrade ## no critic (Subroutines::ProhibitManyArgs)
# use the NEW pg_dumpall so we're comparing apples with apples.
setinstenv($self, "$installdir", $save_env);
+ local $ENV{PGMAXPROTOCOLVERSION} =
+ ($oversion le 'REL9_2_STABLE') ? "3.0" : "latest";
+
system( qq{"$installdir/bin/pg_dumpall" $dump_opts -p $sport -f }
. qq{"$upgrade_loc/origin-$oversion.sql" }
. qq{> "$upgrade_loc/$oversion-dump1.log" 2>&1});
@@ -575,6 +578,8 @@ sub test_upgrade ## no critic (Subroutines::ProhibitManyArgs)
. qq{--new-bindir="$installdir/bin" }
. qq{>> "$upgrade_loc/$oversion-upgrade.log" 2>&1});
+ delete $ENV{PGMAXPROTOCOLVERSION};
+
foreach my $upgradelog (
glob(
"$installdir/pg_upgrade*
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 02:08 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 15:55 ` Re: pgsql: libpq: Grease the protocol by default Andrew Dunstan <[email protected]>
2026-02-24 22:49 ` Re: pgsql: libpq: Grease the protocol by default Andrew Dunstan <[email protected]>
@ 2026-02-24 22:59 ` Jacob Champion <[email protected]>
2026-02-24 23:30 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-25 01:30 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
0 siblings, 2 replies; 27+ messages in thread
From: Jacob Champion @ 2026-02-24 22:59 UTC (permalink / raw)
To: Andrew Dunstan <[email protected]>; +Cc: Tom Lane <[email protected]>; Jelte Fennema-Nio <[email protected]>; [email protected]
On Tue, Feb 24, 2026 at 2:49 PM Andrew Dunstan <[email protected]> wrote:
> Here's what worked for me, even before Jacob's patch of 15 minutes or so
> ago.
Oh, the envvar is clever. You'll probably want to do that only for the
pg_dumpall invocation now that pg_upgrade is patched, though, so we
don't cover up regressions.
--Jacob
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 02:08 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 15:55 ` Re: pgsql: libpq: Grease the protocol by default Andrew Dunstan <[email protected]>
2026-02-24 22:49 ` Re: pgsql: libpq: Grease the protocol by default Andrew Dunstan <[email protected]>
2026-02-24 22:59 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
@ 2026-02-24 23:30 ` Tom Lane <[email protected]>
1 sibling, 0 replies; 27+ messages in thread
From: Tom Lane @ 2026-02-24 23:30 UTC (permalink / raw)
To: Jacob Champion <[email protected]>; +Cc: Andrew Dunstan <[email protected]>; Jelte Fennema-Nio <[email protected]>; [email protected]
Jacob Champion <[email protected]> writes:
> On Tue, Feb 24, 2026 at 2:49 PM Andrew Dunstan <[email protected]> wrote:
>> Here's what worked for me, even before Jacob's patch of 15 minutes or so
>> ago.
> Oh, the envvar is clever. You'll probably want to do that only for the
> pg_dumpall invocation now that pg_upgrade is patched, though, so we
> don't cover up regressions.
I agree with Jacob on both points.
regards, tom lane
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 02:08 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 15:55 ` Re: pgsql: libpq: Grease the protocol by default Andrew Dunstan <[email protected]>
2026-02-24 22:49 ` Re: pgsql: libpq: Grease the protocol by default Andrew Dunstan <[email protected]>
2026-02-24 22:59 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
@ 2026-02-25 01:30 ` Tom Lane <[email protected]>
2026-02-25 02:06 ` Re: pgsql: libpq: Grease the protocol by default Andrew Dunstan <[email protected]>
1 sibling, 1 reply; 27+ messages in thread
From: Tom Lane @ 2026-02-25 01:30 UTC (permalink / raw)
To: Jacob Champion <[email protected]>; +Cc: Andrew Dunstan <[email protected]>; Jelte Fennema-Nio <[email protected]>; [email protected]
Jacob Champion <[email protected]> writes:
> Oh, the envvar is clever. You'll probably want to do that only for the
> pg_dumpall invocation now that pg_upgrade is patched, though, so we
> don't cover up regressions.
I can confirm clean x-version tests on all branches with git tip
and this:
--- TestUpgradeXversion.pm.orig 2025-11-25 07:47:25.000000000 -0500
+++ TestUpgradeXversion.pm 2026-02-24 18:50:29.487530840 -0500
@@ -485,10 +485,14 @@ sub test_upgrade ## no critic (Subrou
# use the NEW pg_dumpall so we're comparing apples with apples.
setinstenv($self, "$installdir", $save_env);
+ local $ENV{PGMAXPROTOCOLVERSION} =
+ ($oversion le 'REL9_2_STABLE') ? "3.0" : "latest";
+
system( qq{"$installdir/bin/pg_dumpall" $dump_opts -p $sport -f }
. qq{"$upgrade_loc/origin-$oversion.sql" }
. qq{> "$upgrade_loc/$oversion-dump1.log" 2>&1});
return if $?;
+ delete $ENV{PGMAXPROTOCOLVERSION};
setinstenv($self, "$other_branch/inst", $save_env);
system( qq{"$other_branch/inst/bin/pg_ctl" -D }
which is Andrew's patch but with the envvar dropped as soon
as possible.
regards, tom lane
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 02:08 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 15:55 ` Re: pgsql: libpq: Grease the protocol by default Andrew Dunstan <[email protected]>
2026-02-24 22:49 ` Re: pgsql: libpq: Grease the protocol by default Andrew Dunstan <[email protected]>
2026-02-24 22:59 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-25 01:30 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
@ 2026-02-25 02:06 ` Andrew Dunstan <[email protected]>
0 siblings, 0 replies; 27+ messages in thread
From: Andrew Dunstan @ 2026-02-25 02:06 UTC (permalink / raw)
To: Tom Lane <[email protected]>; Jacob Champion <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]
On 2026-02-24 Tu 8:30 PM, Tom Lane wrote:
> Jacob Champion <[email protected]> writes:
>> Oh, the envvar is clever. You'll probably want to do that only for the
>> pg_dumpall invocation now that pg_upgrade is patched, though, so we
>> don't cover up regressions.
> I can confirm clean x-version tests on all branches with git tip
> and this:
>
> --- TestUpgradeXversion.pm.orig 2025-11-25 07:47:25.000000000 -0500
> +++ TestUpgradeXversion.pm 2026-02-24 18:50:29.487530840 -0500
> @@ -485,10 +485,14 @@ sub test_upgrade ## no critic (Subrou
>
> # use the NEW pg_dumpall so we're comparing apples with apples.
> setinstenv($self, "$installdir", $save_env);
> + local $ENV{PGMAXPROTOCOLVERSION} =
> + ($oversion le 'REL9_2_STABLE') ? "3.0" : "latest";
> +
> system( qq{"$installdir/bin/pg_dumpall" $dump_opts -p $sport -f }
> . qq{"$upgrade_loc/origin-$oversion.sql" }
> . qq{> "$upgrade_loc/$oversion-dump1.log" 2>&1});
> return if $?;
> + delete $ENV{PGMAXPROTOCOLVERSION};
> setinstenv($self, "$other_branch/inst", $save_env);
>
> system( qq{"$other_branch/inst/bin/pg_ctl" -D }
>
> which is Andrew's patch but with the envvar dropped as soon
> as possible.
>
>
Yep. working for me too.
cheers
andrew
--
Andrew Dunstan
EDB: https://www.enterprisedb.com
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 02:08 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
@ 2026-02-24 17:18 ` Jacob Champion <[email protected]>
2026-02-24 18:13 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
1 sibling, 1 reply; 27+ messages in thread
From: Jacob Champion @ 2026-02-24 17:18 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>
On Mon, Feb 23, 2026 at 6:08 PM Tom Lane <[email protected]> wrote:
> Jacob Champion <[email protected]> writes:
> > On Mon, Feb 23, 2026 at 4:45 PM Tom Lane <[email protected]> wrote:
> >> Also: I was initially baffled why you thought this needs
> >> back-patching, but I guess you have one eye on packagers like
> >> Debian who think they can make older versions use newer libpq.so.
>
> > Right.
>
> Actually, that is going to be harder than you thought, because libpq
> before v18 will spit up on connection option "max_protocol_version".
Ha, right. Luckily the failure is very loud when testing :)
> Fortunately, we long ago had the foresight to invent PQlibVersion,
> so you could make addition of the extra option conditional on
> PQlibVersion(conn) >= 180000 in branches before 18.
Attached is a sample backport for REL_14_STABLE, using that strategy.
Tested with pg_upgrade 9.2-to-14, when linked against both 14.22 and
HEAD versions of libpq. I still need to run a sanity check with the
other 9.x lines to make sure I've selected the right cutoffs.
> Yeah, I came to the same conclusion. I got a clean BF run using
> your patch together with the attached patch for the BF client.
Nice, thanks!
--Jacob
Attachments:
[application/octet-stream] 0001-pg_upgrade-Use-max_protocol_version-3.0-for-older-se.14.patch (5.1K, 2-0001-pg_upgrade-Use-max_protocol_version-3.0-for-older-se.14.patch)
download | inline diff:
From b0a0c381ab83ee39b71c296d367eb06e23569aa5 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 older servers.
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. (This is needed for any distributions that
link older binaries against newer libpqs, such as Debian.) Branches
prior to 18 need an additional version check, for the existence of
max_protocol_version.
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/version.c | 37 +++++++++++++++++++++++++++++++++
4 files changed, 45 insertions(+), 1 deletion(-)
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index e647e71ecaf..14f9cb522db 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -446,6 +446,7 @@ bool check_for_data_types_usage(ClusterInfo *cluster,
bool check_for_data_type_usage(ClusterInfo *cluster,
const char *type_name,
const char *output_path);
+bool protocol_negotiation_supported(const ClusterInfo *cluster);
void new_9_0_populate_pg_largeobject_metadata(ClusterInfo *cluster,
bool check_mode);
void old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster);
diff --git a/src/bin/pg_upgrade/dump.c b/src/bin/pg_upgrade/dump.c
index 90060d0f8eb..ee0ace082ca 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 -f %s",
new_cluster.bindir, cluster_conn_opts(&old_cluster),
+ protocol_negotiation_supported(&old_cluster) ? "" : " -d \"max_protocol_version=3.0\"",
log_opts.verbose ? "--verbose" : "",
GLOBALS_DUMP_FILE);
check_ok();
@@ -42,6 +43,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 7fed0ae1086..f49f3013c38 100644
--- a/src/bin/pg_upgrade/server.c
+++ b/src/bin/pg_upgrade/server.c
@@ -70,6 +70,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/version.c b/src/bin/pg_upgrade/version.c
index ccb012657be..fdddd90bf97 100644
--- a/src/bin/pg_upgrade/version.c
+++ b/src/bin/pg_upgrade/version.c
@@ -325,6 +325,43 @@ old_9_6_check_for_unknown_data_type_usage(ClusterInfo *cluster)
check_ok();
}
+/*
+ * 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);
+
+ /*
+ * Back-branch-specific complication: for libpq versions prior to PG18,
+ * max_protocol_version isn't supported. But we also don't need to worry
+ * about newer protocol versions being used in that case, so just lie and
+ * return true.
+ *
+ * (Checking for a libpq version that's newer than this branch looks very
+ * strange, but distributions are allowed to link older pg_upgrade
+ * binaries against the newest release of libpq.)
+ */
+ if (PQlibVersion() < 180000)
+ return true;
+
+ /*
+ * 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
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 02:08 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 17:18 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
@ 2026-02-24 18:13 ` Jacob Champion <[email protected]>
2026-02-24 18:50 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
0 siblings, 1 reply; 27+ messages in thread
From: Jacob Champion @ 2026-02-24 18:13 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>; Nathan Bossart <[email protected]>
On Tue, Feb 24, 2026 at 9:18 AM Jacob Champion
<[email protected]> wrote:
> I still need to run a sanity check with the
> other 9.x lines to make sure I've selected the right cutoffs.
The cutoffs don't behave the way I thought they would.
Yesterday, I was about to complain that cluster.major_version was
poorly named -- why call it that if you have to pass it through
GET_MAJOR_VERSION() to get at what you want? -- but it does in fact
contain _only_ the major version information, because that's all that
PG_VERSION tells us. And unfortunately we don't save the result of the
version check for the old postgres binary anywhere.
So pg_upgrade will use max_protocol_version=3.0 with all servers v10
and below, in practice. There's nothing wrong with that behavior, but
I think I should switch to a simple `< 1100` check in the code to
avoid misleading people, unless anyone has a better way that won't
significantly increase the cost of the backport. (I could potentially
follow up with an improvement on HEAD, if the cost-benefit makes
sense, but I'm not sure it does.)
--Jacob
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 02:08 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 17:18 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 18:13 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
@ 2026-02-24 18:50 ` Tom Lane <[email protected]>
2026-02-24 18:58 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
0 siblings, 1 reply; 27+ messages in thread
From: Tom Lane @ 2026-02-24 18:50 UTC (permalink / raw)
To: Jacob Champion <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>; Nathan Bossart <[email protected]>
Jacob Champion <[email protected]> writes:
> So pg_upgrade will use max_protocol_version=3.0 with all servers v10
> and below, in practice. There's nothing wrong with that behavior, but
> I think I should switch to a simple `< 1100` check in the code to
> avoid misleading people, unless anyone has a better way that won't
> significantly increase the cost of the backport.
Simple is good here. I don't think we'd buy much by distinguishing
minor versions of already-EOL servers. Also, I suspect that
pg_upgrade can't get the minor version except by starting the server
and asking it --- we don't record anything but major version on-disk.
regards, tom lane
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 02:08 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 17:18 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 18:13 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 18:50 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
@ 2026-02-24 18:58 ` Jacob Champion <[email protected]>
2026-02-24 20:29 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
0 siblings, 1 reply; 27+ messages in thread
From: Jacob Champion @ 2026-02-24 18:58 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>; Nathan Bossart <[email protected]>
On Tue, Feb 24, 2026 at 10:50 AM Tom Lane <[email protected]> wrote:
> Simple is good here. I don't think we'd buy much by distinguishing
> minor versions of already-EOL servers. Also, I suspect that
> pg_upgrade can't get the minor version except by starting the server
> and asking it --- we don't record anything but major version on-disk.
We do store (the major version part of) `pg_ctl --version` at some
point, which we could improve upon, but I agree that adding additional
complexity here doesn't actually give us any benefit.
--Jacob
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 02:08 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 17:18 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 18:13 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 18:50 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 18:58 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
@ 2026-02-24 20:29 ` Jacob Champion <[email protected]>
2026-02-24 20:40 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
0 siblings, 1 reply; 27+ messages in thread
From: Jacob Champion @ 2026-02-24 20:29 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>; Nathan Bossart <[email protected]>
On Tue, Feb 24, 2026 at 10:58 AM Jacob Champion
<[email protected]> wrote:
> We do store (the major version part of) `pg_ctl --version` at some
> point, which we could improve upon, but I agree that adding additional
> complexity here doesn't actually give us any benefit.
Okay, here are the patches I propose. The ones for 18-HEAD check for
PG10 and below, and 14-17 additionally check that libpq >= 18, before
adding max_protocol_version=3.0.
I smoke-tested upgrades from 9.2, 10.1, and 11.0 for all six branches,
and then re-ran that test matrix with pg_upgrade linked against a
greased libpq.
--Jacob
Attachments:
[application/octet-stream] v2-0001-pg_upgrade-Use-max_protocol_version-3.0-for-older.patch (5.0K, 2-v2-0001-pg_upgrade-Use-max_protocol_version-3.0-for-older.patch)
download | inline diff:
From e2a69ee5f96f64ea94f62f9085591129899b3b7c Mon Sep 17 00:00:00 2001
From: Jacob Champion <[email protected]>
Date: Mon, 23 Feb 2026 15:28:32 -0800
Subject: [PATCH v2] 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 older servers.
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. (This is needed for any distributions that
link older binaries against newer libpqs, such as Debian.) Branches
prior to 18 need an additional version check, for the existence of
max_protocol_version.
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 | 18 ++++++++++++++++++
5 files changed, 28 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..047670d4acb 100644
--- a/src/bin/pg_upgrade/version.c
+++ b/src/bin/pg_upgrade/version.c
@@ -28,6 +28,24 @@ 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)
+{
+ /*
+ * The February 2018 patch release (9.3.21, 9.4.16, 9.5.11, 9.6.7, and
+ * 10.2) added support for NegotiateProtocolVersion. But ClusterInfo only
+ * has information about the major version number. To ensure we can still
+ * upgrade older unpatched servers, just assume anything prior to PG11
+ * can't negotiate. It's not possible for those servers to make use of
+ * newer protocols anyway, so nothing is lost.
+ */
+ return (GET_MAJOR_VERSION(cluster->major_version) >= 1100);
+}
+
/*
* old_9_6_invalidate_hash_indexes()
* 9.6 -> 10
--
2.34.1
[application/octet-stream] v2-0001-pg_upgrade-Use-max_protocol_version-3.0-for-older.18.patch (5.0K, 3-v2-0001-pg_upgrade-Use-max_protocol_version-3.0-for-older.18.patch)
download | inline diff:
From 3ba57656ee69d84ca7065a90f3077b499604a6d6 Mon Sep 17 00:00:00 2001
From: Jacob Champion <[email protected]>
Date: Mon, 23 Feb 2026 15:28:32 -0800
Subject: [PATCH v2] 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 older servers.
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. (This is needed for any distributions that
link older binaries against newer libpqs, such as Debian.) Branches
prior to 18 need an additional version check, for the existence of
max_protocol_version.
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 | 18 ++++++++++++++++++
5 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index 69c965bb7d0..22057c22901 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -493,6 +493,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 55f6e7b4d9c..806bf3bef97 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 7eb15bc7d5a..43e6797e14c 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 ee0e2457152..a19ea8445a0 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 3ad5a991a30..56f3dc693fb 100644
--- a/src/bin/pg_upgrade/version.c
+++ b/src/bin/pg_upgrade/version.c
@@ -28,6 +28,24 @@ 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)
+{
+ /*
+ * The February 2018 patch release (9.3.21, 9.4.16, 9.5.11, 9.6.7, and
+ * 10.2) added support for NegotiateProtocolVersion. But ClusterInfo only
+ * has information about the major version number. To ensure we can still
+ * upgrade older unpatched servers, just assume anything prior to PG11
+ * can't negotiate. It's not possible for those servers to make use of
+ * newer protocols anyway, so nothing is lost.
+ */
+ return (GET_MAJOR_VERSION(cluster->major_version) >= 1100);
+}
+
/*
* old_9_6_invalidate_hash_indexes()
* 9.6 -> 10
--
2.34.1
[application/octet-stream] v2-0001-pg_upgrade-Use-max_protocol_version-3.0-for-older.17.patch (4.9K, 4-v2-0001-pg_upgrade-Use-max_protocol_version-3.0-for-older.17.patch)
download | inline diff:
From 1e421e723831bc12f4ab23aa2ede8520bb9c072d Mon Sep 17 00:00:00 2001
From: Jacob Champion <[email protected]>
Date: Mon, 23 Feb 2026 15:28:32 -0800
Subject: [PATCH v2] 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 older servers.
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. (This is needed for any distributions that
link older binaries against newer libpqs, such as Debian.) Branches
prior to 18 need an additional version check, for the existence of
max_protocol_version.
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/version.c | 31 +++++++++++++++++++++++++++++++
4 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index e2b99b49fab..5ad693eaa70 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -482,6 +482,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 29fb45b9289..b14c4ce0ee2 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 -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 b223d5afddf..107e2676397 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/version.c b/src/bin/pg_upgrade/version.c
index 2de6dffccda..276ead84e3f 100644
--- a/src/bin/pg_upgrade/version.c
+++ b/src/bin/pg_upgrade/version.c
@@ -28,6 +28,37 @@ 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)
+{
+ /*
+ * Back-branch-specific complication: for libpq versions prior to PG18,
+ * max_protocol_version isn't supported. But we also don't need to worry
+ * about newer protocol versions being used in that case, so just lie and
+ * return true.
+ *
+ * (Checking for a libpq version that's newer than this branch looks very
+ * strange, but distributions are allowed to link older pg_upgrade
+ * binaries against the newest release of libpq.)
+ */
+ if (PQlibVersion() < 180000)
+ return true;
+
+ /*
+ * The February 2018 patch release (9.3.21, 9.4.16, 9.5.11, 9.6.7, and
+ * 10.2) added support for NegotiateProtocolVersion. But ClusterInfo only
+ * has information about the major version number. To ensure we can still
+ * upgrade older unpatched servers, just assume anything prior to PG11
+ * can't negotiate. It's not possible for those servers to make use of
+ * newer protocols anyway, so nothing is lost.
+ */
+ return (GET_MAJOR_VERSION(cluster->major_version) >= 1100);
+}
+
/*
* old_9_6_invalidate_hash_indexes()
* 9.6 -> 10
--
2.34.1
[application/octet-stream] v2-0001-pg_upgrade-Use-max_protocol_version-3.0-for-older.16.patch (5.1K, 5-v2-0001-pg_upgrade-Use-max_protocol_version-3.0-for-older.16.patch)
download | inline diff:
From 3b5e43a02c680f7e179b09f1d653e7cf6538dbca Mon Sep 17 00:00:00 2001
From: Jacob Champion <[email protected]>
Date: Mon, 23 Feb 2026 15:28:32 -0800
Subject: [PATCH v2] 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 older servers.
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. (This is needed for any distributions that
link older binaries against newer libpqs, such as Debian.) Branches
prior to 18 need an additional version check, for the existence of
max_protocol_version.
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/version.c | 31 +++++++++++++++++++++++++++++++
4 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index 7afa96716ec..44aad96de7b 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -456,6 +456,7 @@ bool check_for_data_types_usage(ClusterInfo *cluster,
bool check_for_data_type_usage(ClusterInfo *cluster,
const char *type_name,
const char *output_path);
+bool protocol_negotiation_supported(const ClusterInfo *cluster);
void old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster);
void old_9_6_check_for_unknown_data_type_usage(ClusterInfo *cluster);
void old_9_6_invalidate_hash_indexes(ClusterInfo *cluster,
diff --git a/src/bin/pg_upgrade/dump.c b/src/bin/pg_upgrade/dump.c
index 6c8c82dca89..a698519029e 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 -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 0bc3d2806b8..75d40626b48 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/version.c b/src/bin/pg_upgrade/version.c
index 403a6d7cfaa..e869d526ba1 100644
--- a/src/bin/pg_upgrade/version.c
+++ b/src/bin/pg_upgrade/version.c
@@ -241,6 +241,37 @@ old_9_6_check_for_unknown_data_type_usage(ClusterInfo *cluster)
check_ok();
}
+/*
+ * 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)
+{
+ /*
+ * Back-branch-specific complication: for libpq versions prior to PG18,
+ * max_protocol_version isn't supported. But we also don't need to worry
+ * about newer protocol versions being used in that case, so just lie and
+ * return true.
+ *
+ * (Checking for a libpq version that's newer than this branch looks very
+ * strange, but distributions are allowed to link older pg_upgrade
+ * binaries against the newest release of libpq.)
+ */
+ if (PQlibVersion() < 180000)
+ return true;
+
+ /*
+ * The February 2018 patch release (9.3.21, 9.4.16, 9.5.11, 9.6.7, and
+ * 10.2) added support for NegotiateProtocolVersion. But ClusterInfo only
+ * has information about the major version number. To ensure we can still
+ * upgrade older unpatched servers, just assume anything prior to PG11
+ * can't negotiate. It's not possible for those servers to make use of
+ * newer protocols anyway, so nothing is lost.
+ */
+ return (GET_MAJOR_VERSION(cluster->major_version) >= 1100);
+}
+
/*
* old_9_6_invalidate_hash_indexes()
* 9.6 -> 10
--
2.34.1
[application/octet-stream] v2-0001-pg_upgrade-Use-max_protocol_version-3.0-for-older.15.patch (5.1K, 6-v2-0001-pg_upgrade-Use-max_protocol_version-3.0-for-older.15.patch)
download | inline diff:
From 1f2cbbdefac2841de1a67d3feec18eaeaed719b3 Mon Sep 17 00:00:00 2001
From: Jacob Champion <[email protected]>
Date: Mon, 23 Feb 2026 15:28:32 -0800
Subject: [PATCH v2] 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 older servers.
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. (This is needed for any distributions that
link older binaries against newer libpqs, such as Debian.) Branches
prior to 18 need an additional version check, for the existence of
max_protocol_version.
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/version.c | 31 +++++++++++++++++++++++++++++++
4 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index 19ca68ed619..803acc696ef 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -449,6 +449,7 @@ bool check_for_data_types_usage(ClusterInfo *cluster,
bool check_for_data_type_usage(ClusterInfo *cluster,
const char *type_name,
const char *output_path);
+bool protocol_negotiation_supported(const ClusterInfo *cluster);
void old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster);
void old_9_6_check_for_unknown_data_type_usage(ClusterInfo *cluster);
void old_9_6_invalidate_hash_indexes(ClusterInfo *cluster,
diff --git a/src/bin/pg_upgrade/dump.c b/src/bin/pg_upgrade/dump.c
index 29b9e44f782..f7d6a537b4f 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 -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 265137e86bf..df165efac40 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/version.c b/src/bin/pg_upgrade/version.c
index 20c61072a42..fa6b945869d 100644
--- a/src/bin/pg_upgrade/version.c
+++ b/src/bin/pg_upgrade/version.c
@@ -241,6 +241,37 @@ old_9_6_check_for_unknown_data_type_usage(ClusterInfo *cluster)
check_ok();
}
+/*
+ * 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)
+{
+ /*
+ * Back-branch-specific complication: for libpq versions prior to PG18,
+ * max_protocol_version isn't supported. But we also don't need to worry
+ * about newer protocol versions being used in that case, so just lie and
+ * return true.
+ *
+ * (Checking for a libpq version that's newer than this branch looks very
+ * strange, but distributions are allowed to link older pg_upgrade
+ * binaries against the newest release of libpq.)
+ */
+ if (PQlibVersion() < 180000)
+ return true;
+
+ /*
+ * The February 2018 patch release (9.3.21, 9.4.16, 9.5.11, 9.6.7, and
+ * 10.2) added support for NegotiateProtocolVersion. But ClusterInfo only
+ * has information about the major version number. To ensure we can still
+ * upgrade older unpatched servers, just assume anything prior to PG11
+ * can't negotiate. It's not possible for those servers to make use of
+ * newer protocols anyway, so nothing is lost.
+ */
+ return (GET_MAJOR_VERSION(cluster->major_version) >= 1100);
+}
+
/*
* old_9_6_invalidate_hash_indexes()
* 9.6 -> 10
--
2.34.1
[application/octet-stream] v2-0001-pg_upgrade-Use-max_protocol_version-3.0-for-older.14.patch (5.1K, 7-v2-0001-pg_upgrade-Use-max_protocol_version-3.0-for-older.14.patch)
download | inline diff:
From 79b399178807bad11d3c3aa8a6cbd47d014f718e Mon Sep 17 00:00:00 2001
From: Jacob Champion <[email protected]>
Date: Mon, 23 Feb 2026 15:28:32 -0800
Subject: [PATCH v2] 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 older servers.
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. (This is needed for any distributions that
link older binaries against newer libpqs, such as Debian.) Branches
prior to 18 need an additional version check, for the existence of
max_protocol_version.
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/version.c | 31 +++++++++++++++++++++++++++++++
4 files changed, 39 insertions(+), 1 deletion(-)
diff --git a/src/bin/pg_upgrade/pg_upgrade.h b/src/bin/pg_upgrade/pg_upgrade.h
index e647e71ecaf..14f9cb522db 100644
--- a/src/bin/pg_upgrade/pg_upgrade.h
+++ b/src/bin/pg_upgrade/pg_upgrade.h
@@ -446,6 +446,7 @@ bool check_for_data_types_usage(ClusterInfo *cluster,
bool check_for_data_type_usage(ClusterInfo *cluster,
const char *type_name,
const char *output_path);
+bool protocol_negotiation_supported(const ClusterInfo *cluster);
void new_9_0_populate_pg_largeobject_metadata(ClusterInfo *cluster,
bool check_mode);
void old_9_3_check_for_line_data_type_usage(ClusterInfo *cluster);
diff --git a/src/bin/pg_upgrade/dump.c b/src/bin/pg_upgrade/dump.c
index 90060d0f8eb..ee0ace082ca 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 -f %s",
new_cluster.bindir, cluster_conn_opts(&old_cluster),
+ protocol_negotiation_supported(&old_cluster) ? "" : " -d \"max_protocol_version=3.0\"",
log_opts.verbose ? "--verbose" : "",
GLOBALS_DUMP_FILE);
check_ok();
@@ -42,6 +43,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 7fed0ae1086..f49f3013c38 100644
--- a/src/bin/pg_upgrade/server.c
+++ b/src/bin/pg_upgrade/server.c
@@ -70,6 +70,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/version.c b/src/bin/pg_upgrade/version.c
index ccb012657be..48fecae47f4 100644
--- a/src/bin/pg_upgrade/version.c
+++ b/src/bin/pg_upgrade/version.c
@@ -325,6 +325,37 @@ old_9_6_check_for_unknown_data_type_usage(ClusterInfo *cluster)
check_ok();
}
+/*
+ * 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)
+{
+ /*
+ * Back-branch-specific complication: for libpq versions prior to PG18,
+ * max_protocol_version isn't supported. But we also don't need to worry
+ * about newer protocol versions being used in that case, so just lie and
+ * return true.
+ *
+ * (Checking for a libpq version that's newer than this branch looks very
+ * strange, but distributions are allowed to link older pg_upgrade
+ * binaries against the newest release of libpq.)
+ */
+ if (PQlibVersion() < 180000)
+ return true;
+
+ /*
+ * The February 2018 patch release (9.3.21, 9.4.16, 9.5.11, 9.6.7, and
+ * 10.2) added support for NegotiateProtocolVersion. But ClusterInfo only
+ * has information about the major version number. To ensure we can still
+ * upgrade older unpatched servers, just assume anything prior to PG11
+ * can't negotiate. It's not possible for those servers to make use of
+ * newer protocols anyway, so nothing is lost.
+ */
+ return (GET_MAJOR_VERSION(cluster->major_version) >= 1100);
+}
+
/*
* old_9_6_invalidate_hash_indexes()
* 9.6 -> 10
--
2.34.1
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 02:08 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 17:18 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 18:13 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 18:50 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 18:58 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 20:29 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
@ 2026-02-24 20:40 ` Tom Lane <[email protected]>
2026-02-24 22:33 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
0 siblings, 1 reply; 27+ messages in thread
From: Tom Lane @ 2026-02-24 20:40 UTC (permalink / raw)
To: Jacob Champion <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>; Nathan Bossart <[email protected]>
Jacob Champion <[email protected]> writes:
> Okay, here are the patches I propose. The ones for 18-HEAD check for
> PG10 and below, and 14-17 additionally check that libpq >= 18, before
> adding max_protocol_version=3.0.
These look sane to me. I might suggest a small wording change in
the <= 17 patches:
- * Back-branch-specific complication: for libpq versions prior to PG18,
+ * Back-branch-specific complication: in libpq versions prior to PG18,
but it probably isn't worth the trouble to edit four separate patches.
regards, tom lane
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 02:08 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 17:18 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 18:13 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 18:50 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 18:58 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 20:29 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 20:40 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
@ 2026-02-24 22:33 ` Jacob Champion <[email protected]>
2026-02-25 10:27 ` Re: pgsql: libpq: Grease the protocol by default Álvaro Herrera <[email protected]>
0 siblings, 1 reply; 27+ messages in thread
From: Jacob Champion @ 2026-02-24 22:33 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>; Nathan Bossart <[email protected]>
On Tue, Feb 24, 2026 at 12:40 PM Tom Lane <[email protected]> wrote:
> These look sane to me. I might suggest a small wording change in
> the <= 17 patches:
>
> - * Back-branch-specific complication: for libpq versions prior to PG18,
> + * Back-branch-specific complication: in libpq versions prior to PG18,
>
> but it probably isn't worth the trouble to edit four separate patches.
By the power of sed, it is done.
And I see that the new release tags are here, so pushed. Thanks for
all the review and testing!
--Jacob
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 01:05 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 02:08 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 17:18 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 18:13 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 18:50 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 18:58 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 20:29 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 20:40 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 22:33 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
@ 2026-02-25 10:27 ` Álvaro Herrera <[email protected]>
0 siblings, 0 replies; 27+ messages in thread
From: Álvaro Herrera @ 2026-02-25 10:27 UTC (permalink / raw)
To: Jacob Champion <[email protected]>; +Cc: Tom Lane <[email protected]>; Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>; Nathan Bossart <[email protected]>
On 2026-Feb-24, Jacob Champion wrote:
> On Tue, Feb 24, 2026 at 12:40 PM Tom Lane <[email protected]> wrote:
> > These look sane to me. I might suggest a small wording change in
> > the <= 17 patches:
> >
> > - * Back-branch-specific complication: for libpq versions prior to PG18,
> > + * Back-branch-specific complication: in libpq versions prior to PG18,
> >
> > but it probably isn't worth the trouble to edit four separate patches.
>
> By the power of sed, it is done.
What I normally do for this kind of thing is commit the typo fix in a
separate commit, then cherry-pick that to other branches, then use
rebase -i to squash it as a fix-up of the previous commit on all
branches.
--
Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/
Y una voz del caos me habló y me dijo
"Sonríe y sé feliz, podría ser peor".
Y sonreí. Y fui feliz.
Y fue peor.
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 23:41 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-24 00:45 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
@ 2026-02-24 01:17 ` Tom Lane <[email protected]>
1 sibling, 0 replies; 27+ messages in thread
From: Tom Lane @ 2026-02-24 01:17 UTC (permalink / raw)
To: Jacob Champion <[email protected]>; +Cc: Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>
I wrote:
> It's not obvious to me where the problem lies.
Ah: the step that is failing is where TestUpgradeXVersion.pm
is trying to make a comparison dump from the old server:
# use the NEW pg_dumpall so we're comparing apples with apples.
setinstenv($self, "$installdir", $save_env);
system( qq{"$installdir/bin/pg_dumpall" $dump_opts -p $sport -f }
. qq{"$upgrade_loc/origin-$oversion.sql" }
. qq{> "$upgrade_loc/$oversion-dump1.log" 2>&1});
return if $?;
So I was right to suspect that we can't fix this without modifying
the buildfarm client.
regards, tom lane
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
@ 2026-02-24 16:17 ` Nathan Bossart <[email protected]>
2026-02-24 17:27 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
1 sibling, 1 reply; 27+ messages in thread
From: Nathan Bossart @ 2026-02-24 16:17 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: Jacob Champion <[email protected]>; Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>
On Mon, Feb 23, 2026 at 06:34:42PM -0500, Tom Lane wrote:
> Jacob Champion <[email protected]> writes:
>> On Mon, Feb 23, 2026 at 2:18 PM Tom Lane <[email protected]> wrote:
>>> Either that or we decide that it's time to throw 9.2 support
>>> overboard (looks like 9.3 and up are fine).
>
>> Well, while I was hacking on a patch I realized that 9.3 (all the way
>> up to 10) is only okay if you're running a sufficiently patched
>> version. PG11 is the first to support negotiation for the whole
>> release line.
>
> Hmm ... and of course the whole point of this exercise is to be sure
> we can pg_upgrade from those out-of-support versions.
I discussed this a bit on the hacking Discord last year, but IMHO we're
reaching a good point to bump up pg_upgrade's oldest supported major
version. I'll probably push to bump it to v10 for the v20 release so that
we can remove many of the version-specific hacks we've built up over the
years. Not to mention that the cross-version tests (the "export
oldinstall" ones described in pg_upgrade's TESTING file, not the buildfarm
ones) don't seem to work past v10 or so because they use various options
that didn't exist or have since been renamed.
Granted, this probably doesn't help the present issue...
--
nathan
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 22:18 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-23 22:51 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 23:34 ` Re: pgsql: libpq: Grease the protocol by default Tom Lane <[email protected]>
2026-02-24 16:17 ` Re: pgsql: libpq: Grease the protocol by default Nathan Bossart <[email protected]>
@ 2026-02-24 17:27 ` Jacob Champion <[email protected]>
0 siblings, 0 replies; 27+ messages in thread
From: Jacob Champion @ 2026-02-24 17:27 UTC (permalink / raw)
To: Nathan Bossart <[email protected]>; +Cc: Tom Lane <[email protected]>; Jelte Fennema-Nio <[email protected]>; [email protected]; Andrew Dunstan <[email protected]>
On Tue, Feb 24, 2026 at 8:17 AM Nathan Bossart <[email protected]> wrote:
> Granted, this probably doesn't help the present issue...
Yeah, we'd need to go all the way to PG11 to avoid it entirely. But
that's okay -- finding and fixing this now means that we don't have to
relitigate it when bumping the default version later (or when
releasing production-grade grease). If PG10 ages out before we finally
decide to do either one, fine.
--Jacob
^ permalink raw reply [nested|flat] 27+ messages in thread
* Re: pgsql: libpq: Grease the protocol by default
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Re: pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
@ 2026-02-23 22:24 ` Jelte Fennema-Nio <[email protected]>
1 sibling, 0 replies; 27+ messages in thread
From: Jelte Fennema-Nio @ 2026-02-23 22:24 UTC (permalink / raw)
To: Jacob Champion <[email protected]>; +Cc: Jacob Champion <[email protected]>; [email protected]
On Mon, 23 Feb 2026 at 22:17, Jacob Champion
<[email protected]> wrote:
> So while this is kind of a nice result, in that it's correctly
> diagnosing the problem, I need to add max_protocol_version=3.0 to the
> connection strings for these upgrades during beta.
Two thoughts:
1. I think we might want the "This indicates a bug in either the
server being contacted..." note to be added to the error even if you
use 3.2/3.3/3.X. It seems pretty helpful in general. It would need a
bit fancier detection though, with strings to search for based on the
actual requested version.
2. Why only force max_protocol_version=3.0 for beta? It sounds like
this would also be an issue once we eventually bump the default
version.
^ permalink raw reply [nested|flat] 27+ messages in thread
end of thread, other threads:[~2026-02-25 10:27 UTC | newest]
Thread overview: 27+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-02-23 18:58 pgsql: libpq: Grease the protocol by default Jacob Champion <[email protected]>
2026-02-23 21:17 ` Jacob Champion <[email protected]>
2026-02-23 22:18 ` Tom Lane <[email protected]>
2026-02-23 22:51 ` Jacob Champion <[email protected]>
2026-02-23 23:34 ` Tom Lane <[email protected]>
2026-02-23 23:41 ` Jacob Champion <[email protected]>
2026-02-24 00:45 ` Tom Lane <[email protected]>
2026-02-24 01:05 ` Jacob Champion <[email protected]>
2026-02-24 02:08 ` Tom Lane <[email protected]>
2026-02-24 15:55 ` Andrew Dunstan <[email protected]>
2026-02-24 22:49 ` Andrew Dunstan <[email protected]>
2026-02-24 22:59 ` Jacob Champion <[email protected]>
2026-02-24 23:30 ` Tom Lane <[email protected]>
2026-02-25 01:30 ` Tom Lane <[email protected]>
2026-02-25 02:06 ` Andrew Dunstan <[email protected]>
2026-02-24 17:18 ` Jacob Champion <[email protected]>
2026-02-24 18:13 ` Jacob Champion <[email protected]>
2026-02-24 18:50 ` Tom Lane <[email protected]>
2026-02-24 18:58 ` Jacob Champion <[email protected]>
2026-02-24 20:29 ` Jacob Champion <[email protected]>
2026-02-24 20:40 ` Tom Lane <[email protected]>
2026-02-24 22:33 ` Jacob Champion <[email protected]>
2026-02-25 10:27 ` Álvaro Herrera <[email protected]>
2026-02-24 01:17 ` Tom Lane <[email protected]>
2026-02-24 16:17 ` Nathan Bossart <[email protected]>
2026-02-24 17:27 ` Jacob Champion <[email protected]>
2026-02-23 22:24 ` Jelte Fennema-Nio <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox