@@ -39,6 +39,7 @@ MOUNT_POINT="/data_migration"
3939LOG_FILE=" /var/log/pg-upgrade-initiate.log"
4040
4141POST_UPGRADE_EXTENSION_SCRIPT=" /tmp/pg_upgrade/pg_upgrade_extensions.sql"
42+ POST_UPGRADE_POSTGRES_PERMS_SCRIPT=" /tmp/pg_upgrade/pg_upgrade_postgres_perms.sql"
4243OLD_PGVERSION=$( run_sql -A -t -c " SHOW server_version;" )
4344
4445SERVER_LC_COLLATE=$( run_sql -A -t -c " SHOW lc_collate;" )
@@ -47,7 +48,6 @@ SERVER_ENCODING=$(run_sql -A -t -c "SHOW server_encoding;")
4748
4849POSTGRES_CONFIG_PATH=" /etc/postgresql/postgresql.conf"
4950PGBINOLD=" /usr/lib/postgresql/bin"
50- PGLIBOLD=" /usr/lib/postgresql/lib"
5151
5252PG_UPGRADE_BIN_DIR=" /tmp/pg_upgrade_bin/$PGVERSION "
5353NIX_INSTALLER_PATH=" /tmp/persistent/nix-installer"
@@ -133,6 +133,22 @@ cleanup() {
133133 echo " Resetting postgres database connection limit"
134134 retry 5 run_sql -c " ALTER DATABASE postgres CONNECTION LIMIT -1;"
135135
136+ echo " Making sure postgres still has access to pg_shadow"
137+ cat << EOF >> $POST_UPGRADE_POSTGRES_PERMS_SCRIPT
138+ DO \$\$
139+ begin
140+ if exists (select from pg_authid where rolname = 'pg_read_all_data') then
141+ execute('grant pg_read_all_data to postgres');
142+ end if;
143+ end
144+ \$\$ ;
145+ grant pg_signal_backend to postgres;
146+ EOF
147+
148+ if [ -f $POST_UPGRADE_POSTGRES_PERMS_SCRIPT ]; then
149+ retry 5 run_sql -f $POST_UPGRADE_POSTGRES_PERMS_SCRIPT
150+ fi
151+
136152 if [ -z " $IS_CI " ] && [ -z " $IS_LOCAL_UPGRADE " ]; then
137153 echo " Unmounting data disk from ${MOUNT_POINT} "
138154 retry 3 umount $MOUNT_POINT
@@ -148,6 +164,14 @@ cleanup() {
148164}
149165
150166function handle_extensions {
167+ if [ -z " $IS_CI " ]; then
168+ retry 5 systemctl restart postgresql
169+ else
170+ CI_start_postgres
171+ fi
172+
173+ retry 8 pg_isready -h localhost -U supabase_admin
174+
151175 rm -f $POST_UPGRADE_EXTENSION_SCRIPT
152176 touch $POST_UPGRADE_EXTENSION_SCRIPT
153177
181205 done
182206}
183207
184- function patch_wrappers {
185- local IS_NIX_UPGRADE=$1
186-
187- WRAPPERS_ENABLED=$( run_sql -A -t -c " SELECT EXISTS(SELECT 1 FROM pg_extension WHERE extname = 'wrappers');" )
188- if [ " $WRAPPERS_ENABLED " = " f" ]; then
189- echo " Wrappers extension not enabled. Skipping."
190- return
191- fi
192-
193- # This is a workaround for older versions of wrappers which don't have the expected
194- # naming scheme, containing the version in their library's file name
195- # e.g. wrappers-0.1.16.so, rather than wrappers.so
196- # pg_upgrade errors out when it doesn't find an equivalent file in the new PG version's
197- # library directory, so we're making sure the new version has the expected (old version's)
198- # file name.
199- # After the upgrade completes, the new version's library file is used.
200- # i.e.
201- # - old version: wrappers-0.1.16.so
202- # - new version: wrappers-0.1.18.so
203- # - workaround to make pg_upgrade happy: copy wrappers-0.1.18.so to wrappers-0.1.16.so
204- if [ " $IS_NIX_UPGRADE " = " true" ]; then
205- if [ -d " $PGLIBOLD " ]; then
206- OLD_WRAPPER_LIB_PATH=$( find " $PGLIBOLD " -name " wrappers*so" -print -quit)
207- OLD_LIB_FILE_NAME=$( basename " $OLD_WRAPPER_LIB_PATH " )
208-
209- find /nix/store/ -name " wrappers*so" -print0 | while read -r -d $' \0' WRAPPERS_LIB_PATH; do
210- if [ -f " $WRAPPERS_LIB_PATH " ]; then
211- WRAPPERS_LIB_PATH_DIR=$( dirname " $WRAPPERS_LIB_PATH " )
212- if [ " $WRAPPERS_LIB_PATH " != " $WRAPPERS_LIB_PATH_DIR /${OLD_LIB_FILE_NAME} " ]; then
213- echo " Copying $WRAPPERS_LIB_PATH to $WRAPPERS_LIB_PATH_DIR /${OLD_LIB_FILE_NAME} "
214- cp " $WRAPPERS_LIB_PATH " " $WRAPPERS_LIB_PATH_DIR /${OLD_LIB_FILE_NAME} " || true
215- fi
216- fi
217- done
218- fi
219- else
220- if [ -d " $PGLIBOLD " ]; then
221- WRAPPERS_LIB_PATH=$( find " $PGLIBNEW " -name " wrappers*so" -print -quit)
222- if [ -f " $WRAPPERS_LIB_PATH " ]; then
223- OLD_WRAPPER_LIB_PATH=$( find " $PGLIBOLD " -name " wrappers*so" -print -quit)
224- if [ -f " $OLD_WRAPPER_LIB_PATH " ]; then
225- LIB_FILE_NAME=$( basename " $OLD_WRAPPER_LIB_PATH " )
226- if [ " $WRAPPERS_LIB_PATH " != " $PGLIBNEW /${LIB_FILE_NAME} " ]; then
227- echo " Copying $WRAPPERS_LIB_PATH to $PGLIBNEW /${LIB_FILE_NAME} "
228- cp " $WRAPPERS_LIB_PATH " " $PGLIBNEW /${LIB_FILE_NAME} " || true
229- fi
230- fi
231- fi
232- fi
233- fi
234- }
235-
236208function initiate_upgrade {
237209 mkdir -p " $MOUNT_POINT "
238210 SHARED_PRELOAD_LIBRARIES=$( cat " $POSTGRES_CONFIG_PATH " | grep shared_preload_libraries | sed " s/shared_preload_libraries =\s\{0,1\}'\(.*\)'.*/\1/" )
@@ -409,8 +381,6 @@ function initiate_upgrade {
409381 export LD_LIBRARY_PATH=" ${PGLIBNEW} "
410382 fi
411383
412- patch_wrappers " $IS_NIX_UPGRADE "
413-
414384 echo " 9. Creating new data directory, initializing database"
415385 chown -R postgres:postgres " $MOUNT_POINT /"
416386 rm -rf " ${PGDATANEW:? } /"
473443 cp -R /etc/postgresql-custom/* " $MOUNT_POINT /conf/"
474444 # removing supautils config as to allow the latest one provided by the latest image to be used
475445 rm -f " $MOUNT_POINT /conf/supautils.conf" || true
446+ rm -rf " $MOUNT_POINT /conf/extension-custom-scripts" || true
476447
477448 # removing wal-g config as to allow it to be explicitly enabled on the new instance
478449 rm -f " $MOUNT_POINT /conf/wal-g.conf"
0 commit comments