Skip to content

Commit 9023432

Browse files
committed
fix pg migration
1 parent 6e0ad5d commit 9023432

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

filefs/usr/local/bin/_migrate_postgres.sh

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,27 @@ echo "Detected PostgreSQL ${old_major} data directory. Starting automated upgrad
6565
mkdir -p "${upgrade_root}" "${socket_dir}"
6666
chmod 700 "${socket_dir}"
6767

68-
rm -f "${pgdata}/postmaster.pid"
68+
# Cleanly shut down the old cluster if it's running or has stale state
69+
# This is required for pg_upgrade to validate the source cluster
70+
echo "Ensuring old PostgreSQL ${old_major} cluster is cleanly shut down..."
71+
rm -f "${pgdata}/postmaster.pid" "${pgdata}/recovery.done"
72+
rm -f "${pgdata}/standby.signal" "${pgdata}/recovery.signal"
73+
74+
# Try to start and shut down the old cluster cleanly if it will start
75+
if "${old_bindir}/postgres" -D "${pgdata}" -c listen_addresses='' \
76+
-c unix_socket_directories="${socket_dir}" \
77+
&>/dev/null &
78+
then
79+
old_pid=$!
80+
sleep 2
81+
if kill -0 "${old_pid}" 2>/dev/null; then
82+
# Server started successfully, shut it down cleanly
83+
"${old_bindir}/pg_ctl" -D "${pgdata}" -m fast stop &>/dev/null || true
84+
wait "${old_pid}" 2>/dev/null || true
85+
fi
86+
fi
87+
88+
sleep 1
6989
mv "${pgdata}" "${backup_dir}"
7090
mkdir -p "${pgdata}"
7191
chmod 700 "${pgdata}"

0 commit comments

Comments
 (0)