File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -65,7 +65,27 @@ echo "Detected PostgreSQL ${old_major} data directory. Starting automated upgrad
6565mkdir -p " ${upgrade_root} " " ${socket_dir} "
6666chmod 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
6989mv " ${pgdata} " " ${backup_dir} "
7090mkdir -p " ${pgdata} "
7191chmod 700 " ${pgdata} "
You can’t perform that action at this time.
0 commit comments