Skip to content

Commit

Permalink
Refs #37797 - ensure we can start PostgreSQL by forcing the old version
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
evgeni committed Sep 12, 2024
1 parent c35c1e3 commit ade30e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion hooks/boot/06-postgresql-upgrade-extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

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

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)
Expand Down
1 change: 1 addition & 0 deletions spec/postgresql_upgrade_hook_context_extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
subject { context.postgresql_upgrade(13) }

before do
allow(File).to receive(:read).with('/var/lib/pgsql/data/PG_VERSION').and_return('12')
allow(context).to receive(:logger).and_return(logger)
allow(context).to receive(:'execute!')
allow(context).to receive(:ensure_packages)
Expand Down

0 comments on commit ade30e4

Please sign in to comment.