PostgreSQL always restart even when version doesn't change, when Patroni enabled
Context
The “restart postgres when version changes” check is not working as expected. I always get a restart but version didn’t change (re-running reconfigure):
[2024-06-28T09:33:23+00:00] INFO: execute[signal to restart postgresql if running version is less than installed one] running why-run run action to support before action
* execute[signal to restart postgresql if running version is less than installed one] action run
- Would execute /opt/gitlab/embedded/bin/patronictl -c /var/opt/gitlab/patroni/patroni.yaml restart --pg-version 14.11 --force postgresql-ha gabriel-geo.c.group-geo-f9c951.internal
[2024-06-28T09:33:23+00:00] INFO: execute[signal to restart postgresql if running version is less than installed one] sending run action to ruby_block[wait for node bootstrap to complete] (before)
execute 'signal to restart postgresql if running version is less than installed one' do
command "#{patroni_helper.ctl_command} -c #{patroni_config_file} restart --pg-version #{pg_helper.version} --force #{node['patroni']['scope']} #{node['patroni']['name']}"
only_if { node['postgresql']['auto_restart_on_version_change'] && patroni_helper.node_status == 'running' }
notifies :run, 'ruby_block[wait for node bootstrap to complete]', :before
end
Notice, the only_if does not check the version number.
Proposal
Adds a new method to PgHelper to query for the running version. The following SQL does that:
SHOW server_version;
14.11
This also works:
gitlab-psql -t -c "SHOW server_version"
Edited by Jason Plum