From 3907c25d7ded2f1988f4dd8d4628650bebe3cdc1 Mon Sep 17 00:00:00 2001 From: Evgeni Golov Date: Tue, 10 Sep 2024 14:52:56 +0200 Subject: [PATCH] Refs #37797 - ensure we can start PostgreSQL by forcing the old version Something (f-m) might have already called switch-to postgresql:13, which - upgraded packages - tried to restart services The later obviously fails as the on-disk data is in the wrong format. --- hooks/boot/06-postgresql-upgrade-extensions.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hooks/boot/06-postgresql-upgrade-extensions.rb b/hooks/boot/06-postgresql-upgrade-extensions.rb index bbc3d5d8..0960d483 100644 --- a/hooks/boot/06-postgresql-upgrade-extensions.rb +++ b/hooks/boot/06-postgresql-upgrade-extensions.rb @@ -2,11 +2,15 @@ module PostgresqlUpgradeHookContextExtension def needs_postgresql_upgrade?(new_version) - File.read('/var/lib/pgsql/data/PG_VERSION').chomp.to_i < new_version.to_i + current_version.to_i < new_version.to_i rescue Errno::ENOENT false end + def current_version + File.read('/var/lib/pgsql/data/PG_VERSION').chomp + end + def os_needs_postgresql_upgrade? el8? && needs_postgresql_upgrade?(13) end @@ -14,6 +18,7 @@ def os_needs_postgresql_upgrade? def postgresql_upgrade(new_version) logger.notice("Performing upgrade of PostgreSQL to #{new_version}") + execute!("dnf module switch-to postgresql:#{current_version} -y", false, true) start_services(['postgresql']) postgres_list = `runuser -l postgres -c 'psql --list --tuples-only --csv'` postgres_databases = CSV.parse(postgres_list)