From 39bdd7b5062f3786cdbed8c6ac44421f78d7e03b Mon Sep 17 00:00:00 2001 From: Wang Yan Date: Fri, 21 May 2021 13:53:39 +0800 Subject: [PATCH] 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 --- make/photon/db/docker-entrypoint.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/make/photon/db/docker-entrypoint.sh b/make/photon/db/docker-entrypoint.sh index 0f765f34f..594f88b49 100644 --- a/make/photon/db/docker-entrypoint.sh +++ b/make/photon/db/docker-entrypoint.sh @@ -27,8 +27,15 @@ if [ "$(ls -A $PGDATA)" ]; then exit 1 fi 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 + 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." if [ "$PGDATAOLD" = "$PGDATA" ]; then find $PGDATA/* -prune ! -name pg${PG_VERSION_NEW} -exec rm -rf {} \;