@@ -631,7 +631,9 @@ migrate_db_using_dump_file() {
631631 safe_mv " $PREFIX /share" postgresql " $PREFIX /share.new"
632632 # restore old backup
633633 safe_cp " $BACKUP_DIR " data " $PREFIX /state/pg"
634- safe_cp " $BACKUP_DIR " bin " $PREFIX "
634+ safe_cp_nolink " $BACKUP_DIR " bin " $PREFIX "
635+ # Ensure restored old binaries are executable by cfpostgres.
636+ chmod 755 " $PREFIX /bin" /* 2> /dev/null || true
635637 on_files cp " $BACKUP_DIR /lib" " $PREFIX /lib"
636638 safe_cp " $BACKUP_DIR /lib" postgresql " $PREFIX /lib"
637639 safe_cp " $BACKUP_DIR /share" postgresql " $PREFIX /share"
@@ -745,6 +747,22 @@ do_migration() {
745747 else
746748 DEBUG=0
747749 fi
750+
751+ # Preflight: verify cfpostgres can execute the old binaries before any
752+ # destructive operation. If not, attempt a one-shot chmod repair.
753+ if ! su cfpostgres -c " LD_LIBRARY_PATH=$BACKUP_DIR /lib/ $BACKUP_DIR /bin/pg_ctl --version" > /dev/null 2>&1 ; then
754+ cf_console echo " cfpostgres cannot execute $BACKUP_DIR /bin/pg_ctl — attempting mode repair"
755+ chmod 755 " $BACKUP_DIR /bin" /* 2> /dev/null || true
756+ chmod 711 " $BACKUP_DIR " " $BACKUP_DIR /bin" 2> /dev/null || true
757+ if ! su cfpostgres -c " LD_LIBRARY_PATH=$BACKUP_DIR /lib/ $BACKUP_DIR /bin/pg_ctl --version" > /dev/null 2>&1 ; then
758+ cf_console echo " ERROR: cfpostgres still cannot execute $BACKUP_DIR /bin/pg_ctl after chmod repair."
759+ ls -la " $BACKUP_DIR /bin/" >&2
760+ cf_console echo " Please fix permissions on $BACKUP_DIR /bin/ and retry the upgrade."
761+ exit 1
762+ fi
763+ cf_console echo " Mode repair succeeded, continuing migration."
764+ fi
765+
748766 cd /tmp
749767 cf_console echo " Migrating database using pg_upgrade utility..."
750768 cf_console echo
0 commit comments