[PG19] pg_upgrade --check passes, then the upgrade fails

Started by shihao zhongabout 1 month ago12 messageshackers
Jump to latest
#1shihao zhong
zhong950419@gmail.com

i hackers,

From 18 to 19, pg_upgrade --check passes for both of these, then the
upgrade fails:

alter role app set standard_conforming_strings = off;
ERROR: non-standard string literals are not supported

create cast (uuid as bytea) with function uuid_send(uuid);
ERROR: cast from type uuid to type bytea already exists

With the patches, --check reports these before the upgrade starts.
0001 lists roles, databases and functions that store a setting the new
cluster rejects.

0002 lists user casts that are now built in. Both ask the new cluster,
so the next removed setting or new cast is caught too.

Both work like check_loadable_libraries(), which collects names from the
old cluster and tries them on the new one.

0003 is a optional test

I think this is a 19 open item.

Thanks,
Shihao

Attachments:

t254362_1
v3-0002-pg_upgrade-Check-user-defined-casts-against-the-n.patchapplication/octet-stream; name=v3-0002-pg_upgrade-Check-user-defined-casts-against-the-n.patchDownload+136-1
v3-0001-pg_upgrade-Check-stored-settings-against-the-new-.patchapplication/octet-stream; name=v3-0001-pg_upgrade-Check-stored-settings-against-the-new-.patchDownload+258-2
v3-0003-pg_upgrade-Test-a-stored-setting-unknown-to-the-n.patchapplication/octet-stream; name=v3-0003-pg_upgrade-Test-a-stored-setting-unknown-to-the-n.patchDownload+33-2
#2Masahiko Sawada
sawada.mshk@gmail.com
In reply to: shihao zhong (#1)
Re: [PG19] pg_upgrade --check passes, then the upgrade fails

On Fri, Oct 23, 2026 at 9:05 PM shihao zhong <zhong950419@gmail.com> wrote:

i hackers,

From 18 to 19, pg_upgrade --check passes for both of these, then the
upgrade fails:

alter role app set standard_conforming_strings = off;
ERROR: non-standard string literals are not supported

create cast (uuid as bytea) with function uuid_send(uuid);
ERROR: cast from type uuid to type bytea already exists

Thank you for the report. I've confirmed that pg_upgrade failed if
there is a role with standard_conforming_string = off or a cast for
uuid to bytea while pg_upgrade --check passes.

With the patches, --check reports these before the upgrade starts.
0001 lists roles, databases and functions that store a setting the new
cluster rejects.

0002 lists user casts that are now built in. Both ask the new cluster,
so the next removed setting or new cast is caught too.

Both patches look like they are trying to resolve these issues in a
generic way, but I'm concerned that they are adding more complexity,
which is not great especially for v19. Also, the 0001 patch seems to
try resolving a wider range of issues than the actual issue that we
currently have. check_for_stored_settings() checks if there is a GUC
parameter that doesn't exist on the new version set to roles,
databases and functions, but it doesn't deal with the
standard_conforming_strings case where a GUC parameter still exists
but is no longer usable. So it ended up hard-coding it:

+ /* Per-role and per-database settings are cluster-wide. */
+ conn = connectToServer(cluster, "template1");
+ res = executeQueryOrDie(conn,
+ "SELECT d.datname, r.rolname, "
+ "       pg_catalog.split_part(s.c, '=', 1) AS name, "
+ "       pg_catalog.lower(s.c) ~ '" SCS_OFF_PATTERN "' AS scs_off "
+ "FROM (SELECT setdatabase, setrole, "
+ "             pg_catalog.unnest(setconfig) AS c "
+ "      FROM pg_catalog.pg_db_role_setting "
+ "      WHERE setdatabase <> 0 OR setrole <> 0) s "
+ "     LEFT JOIN pg_catalog.pg_database d "
+ "            ON d.oid = s.setdatabase "
+ "     LEFT JOIN pg_catalog.pg_roles r "
+ "            ON r.oid = s.setrole "
+ "WHERE pg_catalog.strpos(pg_catalog.split_part(s.c, '=', 1), '.') = 0");

I think that a better fix for v19 would be to check these particular
cases (i.e., standard_conforming_strings = off, escape_string_warning,
and user-defined uuid<->bytea casts) only if the old cluster is 18 or
older, like check_for_not_null_inheritance() and
check_for_gist_inet_ops() do, and we can seek a more generic approach
for v20+.

I think this is a 19 open item.

Agreed.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

#3shihao zhong
zhong950419@gmail.com
In reply to: Masahiko Sawada (#2)
Re: [PG19] pg_upgrade --check passes, then the upgrade fails

Hi Masahiko,

I think that a better fix for v19 would be to check these particular

cases (i.e., standard_conforming_strings = off, escape_string_warning,
and user-defined uuid<->bytea casts) only if the old cluster is 18 or
older, like check_for_not_null_inheritance() and
check_for_gist_inet_ops() do, and we can seek a more generic approach
for v20+.

Thanks for your testing. Okay, let's take care of 19 first. I can create a
different
thread for 20+.

I added two checks next to check_for_gist_inet_ops(). Both run only
when the old cluster is 18 or older. The first lists roles, databases
and functions that set standard_conforming_strings to off or set
escape_string_warning. The second lists user casts between uuid and
bytea.

I attached a version for 19 too.

Attachments:

t254362_3
v4-0001-pg_upgrade-Check-for-settings-and-casts-that-19-c.patchapplication/octet-stream; name=v4-0001-pg_upgrade-Check-for-settings-and-casts-that-19-c.patchDownload+299-1
nocfbot-v4-REL_19-0001-pg_upgrade-Check-for-settings-and-casts-that-19-c.patchapplication/octet-stream; name=nocfbot-v4-REL_19-0001-pg_upgrade-Check-for-settings-and-casts-that-19-c.patchDownload+299-1
#4Kirill Reshke
reshkekirill@gmail.com
In reply to: shihao zhong (#3)
Re: [PG19] pg_upgrade --check passes, then the upgrade fails

On Thu, 29 Oct 2026 at 07:11, shihao zhong <zhong950419@gmail.com> wrote:

Hi Masahiko,

I think that a better fix for v19 would be to check these particular

cases (i.e., standard_conforming_strings = off, escape_string_warning,
and user-defined uuid<->bytea casts) only if the old cluster is 18 or
older, like check_for_not_null_inheritance() and
check_for_gist_inet_ops() do, and we can seek a more generic approach
for v20+.

Thanks for your testing. Okay, let's take care of 19 first. I can create a different
thread for 20+.

I added two checks next to check_for_gist_inet_ops(). Both run only
when the old cluster is 18 or older. The first lists roles, databases
and functions that set standard_conforming_strings to off or set
escape_string_warning. The second lists user casts between uuid and
bytea.

I attached a version for 19 too.

Hi

I reviewed v4 and found some more cases that v4 does not cover. Its
when setting is still present, but value is not supported:

alter role app set default_toast_compression = lz4;
--> ERROR: invalid value for parameter "default_toast_compression": "lz4"
--> HINT: Available values: pglz.

alter role app set wal_compression = lz4; -- also zstd
--> ERROR: invalid value for parameter "wal_compression": "lz4"

v4 --check passes while pg_upgrade itself does not.
So I think we need separate value validation check, not this +
"'^standard_conforming_strings=(0|f|fa|fal|fals|false|n|no|of|off)$' "
\
One option is to actually try run set_config on new cluster for each
GUC-value pair. Attached does that. Its PoC, and its partally
AI-generated, but in my by-hand A/B test it does catch incompatable
setting, while bening cluster upgrade succeeds

--
Best regards,
Kirill Reshke

Attachments:

0002-stored-setting-values-on-v4.diffapplication/octet-stream; name=0002-stored-setting-values-on-v4.diffDownload+198-0
#5Kirill Reshke
reshkekirill@gmail.com
In reply to: Kirill Reshke (#4)
Re: [PG19] pg_upgrade --check passes, then the upgrade fails

On Thu, 29 Oct 2026 at 09:57, Kirill Reshke <reshkekirill@gmail.com> wrote:

On Thu, 29 Oct 2026 at 07:11, shihao zhong <zhong950419@gmail.com> wrote:

Hi Masahiko,

I think that a better fix for v19 would be to check these particular

cases (i.e., standard_conforming_strings = off, escape_string_warning,
and user-defined uuid<->bytea casts) only if the old cluster is 18 or
older, like check_for_not_null_inheritance() and
check_for_gist_inet_ops() do, and we can seek a more generic approach
for v20+.

Thanks for your testing. Okay, let's take care of 19 first. I can create a different
thread for 20+.

I added two checks next to check_for_gist_inet_ops(). Both run only
when the old cluster is 18 or older. The first lists roles, databases
and functions that set standard_conforming_strings to off or set
escape_string_warning. The second lists user casts between uuid and
bytea.

I attached a version for 19 too.

Hi

I reviewed v4 and found some more cases that v4 does not cover. Its
when setting is still present, but value is not supported:

alter role app set default_toast_compression = lz4;
--> ERROR: invalid value for parameter "default_toast_compression": "lz4"
--> HINT: Available values: pglz.

alter role app set wal_compression = lz4; -- also zstd
--> ERROR: invalid value for parameter "wal_compression": "lz4"

v4 --check passes while pg_upgrade itself does not.
So I think we need separate value validation check, not this +
"'^standard_conforming_strings=(0|f|fa|fal|fals|false|n|no|of|off)$' "
\
One option is to actually try run set_config on new cluster for each
GUC-value pair. Attached does that. Its PoC, and its partally
AI-generated, but in my by-hand A/B test it does catch incompatable
setting, while bening cluster upgrade succeeds

--
Best regards,
Kirill Reshke

v4+mydiff misses v11 -> v20 default_with_oids upgrade

pg_upgrade_utility.log:
ALTER ROLE "oidsuser" SET "default_with_oids" TO 'on';
psql: .../pg_upgrade_dump_globals.sql:36: ERROR:
tables declared WITH OIDS are not supported

new-cluster server log:
2026-10-29 05:37:20.339 UTC [4002982] ERROR:
tables declared WITH OIDS are not supported
2026-10-29 05:37:20.339 UTC [4002982] STATEMENT:
ALTER ROLE "oidsuser" SET "default_with_oids" TO 'on';

But I think we can ignore this problem due to lack of actual complains
across all this years after WITH OIDS removal

--
Best regards,
Kirill Reshke

#6shihao zhong
zhong950419@gmail.com
In reply to: Kirill Reshke (#5)
Re: [PG19] pg_upgrade --check passes, then the upgrade fails

Hi Kirill,

Thanks for reviewing v4 and for the PoC.

I think the lz4 and zstd cases are not new in 19. 18 to 18 fails the same
way
when the new build has no lz4 or zstd.

I want to limit this thread for pg19 regression, maybe your patch can
target 20?

Thanks,
Shihao

#7Kirill Reshke
reshkekirill@gmail.com
In reply to: shihao zhong (#6)
Re: [PG19] pg_upgrade --check passes, then the upgrade fails

On Fri, 30 Oct 2026 at 07:27, shihao zhong <zhong950419@gmail.com> wrote:

Hi Kirill,

Thanks for reviewing v4 and for the PoC.

I think the lz4 and zstd cases are not new in 19. 18 to 18 fails the same way
when the new build has no lz4 or zstd.

I want to limit this thread for pg19 regression, maybe your patch can target 20?

Yes, my bad, I didn't read the thread carefully. Let's continue on
some other v20 thread, is there any already?

--
Best regards,
Kirill Reshke

#8Masahiko Sawada
sawada.mshk@gmail.com
In reply to: shihao zhong (#3)
Re: [PG19] pg_upgrade --check passes, then the upgrade fails

On Wed, Oct 28, 2026 at 7:11 PM shihao zhong <zhong950419@gmail.com> wrote:

Hi Masahiko,

I think that a better fix for v19 would be to check these particular

cases (i.e., standard_conforming_strings = off, escape_string_warning,
and user-defined uuid<->bytea casts) only if the old cluster is 18 or
older, like check_for_not_null_inheritance() and
check_for_gist_inet_ops() do, and we can seek a more generic approach
for v20+.

Thanks for your testing. Okay, let's take care of 19 first. I can create a different
thread for 20+.

I added two checks next to check_for_gist_inet_ops(). Both run only
when the old cluster is 18 or older. The first lists roles, databases
and functions that set standard_conforming_strings to off or set
escape_string_warning. The second lists user casts between uuid and
bytea.

I attached a version for 19 too.

I've researched this issue further with AI assistance, and I now
wonder if it's worth fixing these issues for v19, even in the
particular-case way I suggested before.

For instance, we introduced casts between bytea and int2/4/8 in v18
but didn't add any check to pg_upgrade, and I've not found any report
of an upgrade failing because of it. I confirmed that upgrading from
v17 to v18 fails in exactly the same way (--check passes, then the
restore fails) if the user had created such a cast. Similarly, we have
removed or restricted GUCs in past major versions without adding
checks. So while it would be better if pg_upgrade --check detected
such cases, whether we need to do something for v19 depends on how
likely users are to face this issue in practice, and I think it's
unlikely given these precedents. Therefore, I'm now inclined to think
these are not v19 bugs we must fix before release. For master, it
might be a good idea to improve pg_upgrade checks in a more general
way, so I think we can continue the discussion for v20 and later.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

#9T, Adesh
adeshdb@amazon.com
In reply to: Masahiko Sawada (#8)
Re: [PG19] pg_upgrade --check passes, then the upgrade fails

Hi all,

One more case for the general check in master: privileges granted on a
GUC that the new version removed (pg_parameter_acl). pg_upgrade --check
passes, and the globals restore then fails.

Repro, REL_18_STABLE (03ba8e5) -> master (328a9a1):

-- old cluster (18)
CREATE ROLE r1;
GRANT SET ON PARAMETER escape_string_warning TO r1;

$ pg_upgrade ... --check
*Clusters are compatible*
$ pg_upgrade ...
Restoring global objects in the new cluster *failure*

GRANT SET ON PARAMETER "escape_string_warning" TO "r1";
ERROR: unrecognized configuration parameter "escape_string_warning"

The same grant on work_mem upgrades fine, and revoking the grant before
the upgrade avoids the failure.

agree it does not need to block 19. But when the generic check for
stored settings is done, it seems worth reading pg_parameter_acl as well
as pg_db_role_setting.

Regards,
Adesh

#10shihao zhong
zhong950419@gmail.com
In reply to: Masahiko Sawada (#8)
Re: [PG19] pg_upgrade --check passes, then the upgrade fails

Hi Masahiko,

Fair point on the casts. The bytea and int casts in 18 are the same
case, so I'm fine dropping the cast check.

I'd still like to fix the standard_conforming_strings part in 19.
Commit 45762084545 says "pg_upgrade will work transparently even if
the source installation has standard_conforming_strings = off". That
holds for the server default. It does not hold when a role, database
or function sets it. So this looks like a gap in that commit, not an
old class of problem.

Stored settings that break an upgrade do get reported. 69d5ca484b6 was
back-patched in 2021 after two separate reports of ALTER ROLE ... SET
role failing an upgrade.

If you agree, I'll send a v5 with only that check. If you still think
it's not worth it for 19, I'm fine with that and will move on to the
general check for 20.

Thanks,
Shihao

#11Masahiko Sawada
sawada.mshk@gmail.com
In reply to: shihao zhong (#10)
Re: [PG19] pg_upgrade --check passes, then the upgrade fails

On Sat, Oct 31, 2026 at 5:21 PM shihao zhong <zhong950419@gmail.com> wrote:

Hi Masahiko,

Fair point on the casts. The bytea and int casts in 18 are the same
case, so I'm fine dropping the cast check.

I'd still like to fix the standard_conforming_strings part in 19.
Commit 45762084545 says "pg_upgrade will work transparently even if
the source installation has standard_conforming_strings = off". That
holds for the server default. It does not hold when a role, database
or function sets it. So this looks like a gap in that commit, not an
old class of problem.

Stored settings that break an upgrade do get reported. 69d5ca484b6 was
back-patched in 2021 after two separate reports of ALTER ROLE ... SET
role failing an upgrade.

If you agree, I'll send a v5 with only that check. If you still think
it's not worth it for 19, I'm fine with that and will move on to the
general check for 20.

I understand that the current behavior looks inconsistent with what
the commit message of 45762084545 says.

That said, looking at the past cases, we have several similar ones.
The most recent one is default_with_oids: it became a dummy GUC in v12
and setting it to true has been effectively unusable since then, so it
has exactly the same problem. So I think we can consider the
standard_conforming_strings case not a new problem either. I don't see
a reason why standard_conforming_strings is more likely to be attached
to a database, role, or function than those GUCs, and I could not find
any report of pg_upgrade failing for this reason.

As for 69d5ca484b6, I'm not sure that we can use it as a precedent.
What we chose there was to make the restore succeed by relaxing the
GUC check hooks for PGC_S_TEST, not to make pg_upgrade --check detect
the problem.

Also, even if we fix standard_conforming_strings in v19, IIUC holes
remain. For example, force_parallel_mode was renamed in v16 without an
alias, so an upgrade from v15 or earlier with it attached to a role
fails the same way, and v19's pg_upgrade is also used for upgrades
from such older versions. So if we fix this, I think we need to cover
not just standard_conforming_strings but all GUCs whose compatibility
was broken across major versions.

Given that, while I agree that it would be good behavior for
pg_upgrade --check to detect these cases, I'm not sure we can call the
current behavior a v19 bug. Others may think differently, but I think
it's better to discuss and address this on master.

Regards,

--
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com

#12shihao zhong
zhong950419@gmail.com
In reply to: Masahiko Sawada (#11)
Re: [PG19] pg_upgrade --check passes, then the upgrade fails

Hi Masahiko,

Thanks for digging into the older cases.

I started a thread for master in [1]/messages/by-id/CAGRkXqRzM-68S9OhtLsTscZ_hhpHhy=ArWCdmp5GxRxo+UBmig@mail.gmail.com. It tries each stored setting
on the new cluster. That covers both of your examples and Adesh's
GRANT SET case.

[1]: /messages/by-id/CAGRkXqRzM-68S9OhtLsTscZ_hhpHhy=ArWCdmp5GxRxo+UBmig@mail.gmail.com
/messages/by-id/CAGRkXqRzM-68S9OhtLsTscZ_hhpHhy=ArWCdmp5GxRxo+UBmig@mail.gmail.com

Thanks,
Shihao