pg_upgrade --check: catch stored settings the new cluster rejects

Started by shihao zhong16 days ago1 messageshackers
Jump to latest
#1shihao zhong
zhong950419@gmail.com

Hi hackers,

pg_dump turns the settings stored on roles, db and functions
into ALTER ROLE ... SET and similar commands. It turns privileges on
parameters into GRANT SET. pg_upgrade --check does not look at any of
these. If the new server rejects one, --check passes and the upgrade
then fails during the restore. For example, force_parallel_mode was
renamed in 16 with no alias. A role from 15 with it set cannot be
restored. Neither can a role with default_with_oids = on.

This came up for 19 in [1]/messages/by-id/CAGRkXqT+5+mQhoKZFTiM4yOZtVV=NW506vDwFtVeG+VmL_W5wQ@mail.gmail.com, where 45762084545 made
standard_conforming_strings = off an error. Masahiko pointed out in [2]/messages/by-id/CAD21AoCwNAtMZuK_x78V57S+Cc8j2nCWStipYQVmBXrFtXCsCw@mail.gmail.com
that the problem is older, and that a fix should cover all such
settings on master. Adesh found the same failure with GRANT SET [3]/messages/by-id/SACPR18MB28916173BA2C27CB74FA4CFF57DE6D2@SACPR18MB289161.namprd18.prod.outlook.com.

The patch asks the new server instead of keeping a list of removed
names. For each stored setting, it runs the command the restore would
run on the new cluster. Each runs under a savepoint, and all of it is
rolled back. Failures go to stored_settings.txt:

role "fpmuser": force_parallel_mode=on: unrecognized configuration
parameter "force_parallel_mode"

Kirill suggested checking each setting with set_config() in [4]/messages/by-id/CALdSSPj2bZzVuduzn8=_7s0ukaxnWVjAkKuMfL0d_PLwCQ8ixQ@mail.gmail.com,
thanks. I used the real command instead. A setting like
default_tablespace can point at an object that is not restored yet. The
restore only warns about that, but set_config() fails. Since 69d5ca484b6
the check hooks decide which checks need the database state.

The downside is cost. It needs a transaction in the new cluster, and a
query per database in the old one for function settings. A list of
removed names is cheaper, but it has to be updated for every release.

0001 moves makeAlterConfigCommand() to fe_utils, so pg_upgrade builds
the same command as pg_dump. No functional change. 0002 adds the check
and a TAP test.

I tried upgrades from 14 and 18 to master. Each bad case was caught.
Without the patch the upgrade failed with the same error. Settings that
point at a tablespace or a text search configuration still pass.

[1]: /messages/by-id/CAGRkXqT+5+mQhoKZFTiM4yOZtVV=NW506vDwFtVeG+VmL_W5wQ@mail.gmail.com
/messages/by-id/CAGRkXqT+5+mQhoKZFTiM4yOZtVV=NW506vDwFtVeG+VmL_W5wQ@mail.gmail.com
[2]: /messages/by-id/CAD21AoCwNAtMZuK_x78V57S+Cc8j2nCWStipYQVmBXrFtXCsCw@mail.gmail.com
/messages/by-id/CAD21AoCwNAtMZuK_x78V57S+Cc8j2nCWStipYQVmBXrFtXCsCw@mail.gmail.com
[3]: /messages/by-id/SACPR18MB28916173BA2C27CB74FA4CFF57DE6D2@SACPR18MB289161.namprd18.prod.outlook.com
/messages/by-id/SACPR18MB28916173BA2C27CB74FA4CFF57DE6D2@SACPR18MB289161.namprd18.prod.outlook.com
[4]: /messages/by-id/CALdSSPj2bZzVuduzn8=_7s0ukaxnWVjAkKuMfL0d_PLwCQ8ixQ@mail.gmail.com
/messages/by-id/CALdSSPj2bZzVuduzn8=_7s0ukaxnWVjAkKuMfL0d_PLwCQ8ixQ@mail.gmail.com

Thanks,
Shihao

Attachments:

t254621_1
v1-0002-pg_upgrade-Check-stored-settings-against-the-new-.patchapplication/octet-stream; name=v1-0002-pg_upgrade-Check-stored-settings-against-the-new-.patchDownload+508-1
v1-0001-Move-makeAlterConfigCommand-to-fe_utils.patchapplication/octet-stream; name=v1-0001-Move-makeAlterConfigCommand-to-fe_utils.patchDownload+112-114