Cant update postgresql - permission denied analyze_new_cluster.sh

The process to upgrade my postgresql via

sudo gitlab-ctl pg-upgrade

fails with this message

Creating script to analyze new cluster Could not open file “./analyze_new_cluster.sh”: Permission denied

This file owner is ssh_keys and has all the permissions
I am logged into my server as root and run as sudo

I even tried to change file owner to root.

I am really stuck as I now cant keep gitlab upto date
Any tips as to what I am doing wrong

Hi,

The owner and permissions of this file should be the same as mine below:

ls -lh /var/opt/gitlab/postgresql
-rwx------  1 gitlab-psql gitlab-psql  795 Aug 24 21:09 analyze_new_cluster.sh

and the contents of the script will be similar as below:

#!/bin/sh

echo 'This script will generate minimal optimizer statistics rapidly'
echo 'so your system is usable, and then gather statistics twice more'
echo 'with increasing accuracy.  When it is done, your system will'
echo 'have the default level of optimizer statistics.'
echo

echo 'If you have used ALTER TABLE to modify the statistics target for'
echo 'any tables, you might want to remove them and restore them after'
echo 'running this script because they will delay fast statistics generation.'
echo

echo 'If you would like default statistics as quickly as possible, cancel'
echo 'this script and run:'
echo '    "/opt/gitlab/embedded/postgresql/13/bin/vacuumdb" --all --analyze-only'
echo

"/opt/gitlab/embedded/postgresql/13/bin/vacuumdb" --all --analyze-in-stages
echo

echo 'Done'

mine shows Postgres 13, so you’ll need to edit and make it for the version you have that is currently running. You can check that with:

gitlab-psql --version

for example, checking the path from the script:

ls /opt/gitlab/embedded/postgresql/
12  13

shows 12 and 13 because I used to be on Postgres 12 until I upgraded it to 13 when it appeared in a 15.x version. So amend accordingly based on your install.

If the contents of the script is not similar as what I posted above, considering ssh_keys as the owner of the file looks strange to me, I’m curious as to whether this file has been replaced with something entirely different causing your upgrade to fail. Either that, or it’s just a simple permissions issue.