diff --git a/hooks/boot/01-kafo-hook-extensions.rb b/hooks/boot/01-kafo-hook-extensions.rb index 32826ff4..25b13e2b 100644 --- a/hooks/boot/01-kafo-hook-extensions.rb +++ b/hooks/boot/01-kafo-hook-extensions.rb @@ -113,6 +113,7 @@ def execute!(command, do_say = true, do_log = true) log_and_say(:error, "#{command} failed! Check the output for error!", do_say, do_log) exit 1 end + stdout_stderr end def execute_as!(user, command, do_say = true, do_log = true) diff --git a/hooks/boot/06-postgresql-upgrade-extensions.rb b/hooks/boot/06-postgresql-upgrade-extensions.rb index fe76c8b1..2d26577a 100644 --- a/hooks/boot/06-postgresql-upgrade-extensions.rb +++ b/hooks/boot/06-postgresql-upgrade-extensions.rb @@ -43,6 +43,11 @@ def postgresql_upgrade(new_version) execute_as!('postgres', 'vacuumdb --all --analyze-in-stages', false, true) + if new_version.to_i == 13 + logger.notice("Updating ownership of the evr extension if upgrading to postgres version 13") + execute!("runuser -l postgres -c \"psql -d foreman -c \\\"UPDATE pg_extension SET extowner = (SELECT oid FROM pg_authid WHERE rolname='foreman') WHERE extname='evr';\\\"\"", false, true) + end + logger.notice("Upgrade to PostgreSQL #{new_version} completed") end diff --git a/hooks/pre/35-change-evr-extension-ownership.rb b/hooks/pre/35-change-evr-extension-ownership.rb new file mode 100644 index 00000000..fd667f9e --- /dev/null +++ b/hooks/pre/35-change-evr-extension-ownership.rb @@ -0,0 +1,5 @@ +logger.notice("Updating ownership of the evr extension if it is enabled") +result = execute!("runuser -l postgres -c \"psql -d foreman -c \\\"SELECT 1 from pg_extension WHERE extname='evr';\\\"\"", false, true) +unless (result.include?('(0 rows)')) + execute!("runuser -l postgres -c \"psql -d foreman -c \\\"UPDATE pg_extension SET extowner = (SELECT oid FROM pg_authid WHERE rolname='foreman') WHERE extname='evr';\\\"\"", false, true) +end