pg upgrade failure handling (#14934)

To ensure the upgrade execution idempotence, it needs to clean the $PGDATANEW on pg_upgrade failure.
Otherwise, the upgrade will skip the upgrade process from the second time launch as the exist of $PGDATANEW.

Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2021-05-21 13:53:39 +08:00 committed by GitHub
parent 6c14e699b1
commit 39bdd7b506
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,8 +27,15 @@ if [ "$(ls -A $PGDATA)" ]; then
exit 1 exit 1
fi fi
initPG $PGDATANEW false initPG $PGDATANEW false
# because of the 'set -e', the upgrade failure will break execution. # it needs to clean the $PGDATANEW on upgrade failure
set +e
./$CUR/upgrade.sh --old-bindir $PGBINOLD --old-datadir $PGDATAOLD --new-datadir $PGDATANEW ./$CUR/upgrade.sh --old-bindir $PGBINOLD --old-datadir $PGDATAOLD --new-datadir $PGDATANEW
if [ $? -ne 0 ]; then
echo "remove the $PGDATANEW after fail to upgrade"
rm -rf $PGDATANEW
exit 1
fi
set -e
echo "remove the $PGDATAOLD after upgrade success." echo "remove the $PGDATAOLD after upgrade success."
if [ "$PGDATAOLD" = "$PGDATA" ]; then if [ "$PGDATAOLD" = "$PGDATA" ]; then
find $PGDATA/* -prune ! -name pg${PG_VERSION_NEW} -exec rm -rf {} \; find $PGDATA/* -prune ! -name pg${PG_VERSION_NEW} -exec rm -rf {} \;