From 7e637786b3e3910ca06052a0e40f297a15314cd4 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Fri, 5 May 2023 15:11:52 -0400 Subject: [PATCH] upgrade-postgresql: Only try to start new cluster if it is stopped. pg_upgradecluster will start the cluster if the old cluster was started before it ran, or if there are post-upgrade scripts to run. Because neither of those are fully under our control, only attempt to start the new cluster if it isn't already. --- scripts/setup/upgrade-postgresql | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/setup/upgrade-postgresql b/scripts/setup/upgrade-postgresql index 3302cac04d..51a0f897d5 100755 --- a/scripts/setup/upgrade-postgresql +++ b/scripts/setup/upgrade-postgresql @@ -59,7 +59,14 @@ SCRIPTS_PATH=$(grep -o "/var/log/postgresql/pg_upgradecluster-$UPGRADE_FROM-$UPG crudini --set /etc/zulip/zulip.conf postgresql version "$UPGRADE_TO" # Make sure the new PostgreSQL is running -pg_ctlcluster "$UPGRADE_TO" main start +start_main_cluster="$( + pg_lsclusters --json \ + | jq --arg pg_version "$UPGRADE_TO" -r \ + '.[] | select((.version|tostring == $ARGS.named.pg_version) and (.cluster == "main") and (.running != 1)) | .cluster' +)" +if [ -n "$start_main_cluster" ]; then + pg_ctlcluster "$UPGRADE_TO" main start +fi # Update the statistics su postgres -c "/usr/lib/postgresql/$UPGRADE_TO/bin/vacuumdb --all --analyze-only --jobs 10"