Skip to content

Commit

Permalink
Fixes #37797 - ensure PostgreSQL upgrade uses the right locales
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeni committed Sep 9, 2024
1 parent 776275a commit 2319705
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion hooks/boot/06-postgresql-upgrade-extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def os_needs_postgresql_upgrade?
def postgresql_upgrade(new_version)
logger.notice("Performing upgrade of PostgreSQL to #{new_version}")

start_services(['postgresql'])
(_name, _owner, _enconding, collate, ctype, _privileges) = `runuser -l postgres -c 'psql -lt | grep -E "^\s+postgres"'`.chomp.split('|').map(&:strip)

stop_services

logger.notice("Upgrading PostgreSQL packages")
Expand All @@ -35,7 +38,7 @@ def postgresql_upgrade(new_version)
# see https://bugzilla.redhat.com/show_bug.cgi?id=1935301
execute!("sed -i '/^data_directory/d' /var/lib/pgsql/data/postgresql.conf", false, true)

execute_as!('postgres', 'postgresql-setup --upgrade', false, true)
execute_as!('postgres', "PGSETUP_INITDB_OPTIONS=\"--lc-collate=#{collate} --lc-ctype=#{ctype} --locale=#{collate}\" postgresql-setup --upgrade", false, true)

logger.notice("Analyzing the new PostgreSQL cluster")

Expand Down
3 changes: 2 additions & 1 deletion spec/postgresql_upgrade_hook_context_extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
allow(context).to receive(:ensure_packages)
allow(context).to receive(:stop_services)
allow(context).to receive(:start_services)
allow(context).to receive(:'`').with("runuser -l postgres -c 'psql -lt | grep -E \"^\s+postgres\"'").and_return(' postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | ')
allow(logger).to receive(:notice)
end

Expand All @@ -57,7 +58,7 @@

it 'runs postgresql-setup --upgrade' do
expect(subject).to be_nil
expect(context).to have_received(:'execute!').with("runuser -l postgres -c 'postgresql-setup --upgrade'", false, true)
expect(context).to have_received(:'execute!').with("runuser -l postgres -c 'PGSETUP_INITDB_OPTIONS=\"--lc-collate=en_US.UTF-8 --lc-ctype=en_US.UTF-8 --locale=en_US.UTF-8\" postgresql-setup --upgrade'", false, true)
end

it 'runs vacuumdb --all --analyze-in-stages' do
Expand Down

0 comments on commit 2319705

Please sign in to comment.