harbor/make/photon/db/upgrade.sh
Wang Yan 86185989cf
support pg upgrade (#14846)
1, use the pg source and photon spec to build postgres 9.6
2, install 9.6 on the photon 4.0
3, then leverage pg_upgrade to handle the pg major version migration

Signed-off-by: Wang Yan <wangyan@vmware.com>
2021-05-20 16:25:50 +08:00

46 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
PGBINOLD="/usr/local/pg96/bin/"
PGBINNEW="/usr/bin"
PGDATAOLD=""
PGDATANEW=""
while [[ "$#" -gt 0 ]]; do
case $1 in
-b|--old-datadir) PGDATAOLD="$2"; shift ;;
-B|--new-datadir) PGDATANEW="$2"; shift ;;
-d|--old-bindir) PGBINOLD="$2"; shift ;;
-D|--new-bindir) PGBINNEW="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
if [ "$PGDATAOLD" = "" ] || [ "$PGDATANEW" = "" ]; then
echo "required parameter is missing: $PGDATAOLD, $PGDATANEW"
exit 1
fi
export PGDATAOLD=$PGDATAOLD
export PGDATANEW=$PGDATANEW
export PGBINNEW=$PGBINNEW
export PGBINOLD=$PGBINOLD
echo 'start to upgrade.'
cd /tmp
${PGBINNEW}/pg_upgrade \
--old-datadir=$PGDATAOLD \
--new-datadir=$PGDATANEW \
--old-bindir=$PGBINOLD \
--new-bindir=$PGBINNEW \
--old-options '-c config_file=$PGDATAOLD/postgresql.conf' \
--new-options '-c config_file=$PGDATANEW/postgresql.conf'
if [ $? -ne 0 ]; then
echo 'fail to upgrade.'
cat /tmp/pg_upgrade_internal.log
exit 1
fi
cp $PGDATAOLD/pg_hba.conf $PGDATANEW/pg_hba.conf
echo 'success to upgrade.'