mirror of
https://github.com/goharbor/harbor
synced 2024-09-21 11:48:35 +00:00
86185989cf
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>
53 lines
1.8 KiB
Bash
53 lines
1.8 KiB
Bash
#!/bin/bash
|
|
set -e
|
|
|
|
source $PWD/initdb.sh
|
|
|
|
CUR=$PWD
|
|
PG_VERSION_OLD=$1
|
|
PG_VERSION_NEW=$2
|
|
|
|
PGBINOLD="/usr/local/pg${PG_VERSION_OLD}/bin"
|
|
|
|
PGDATAOLD=${PGDATA}/pg${PG_VERSION_OLD}
|
|
PGDATANEW=${PGDATA}/pg${PG_VERSION_NEW}
|
|
# to handle the PG 9.6 only
|
|
if [ -s $PGDATA/PG_VERSION ]; then
|
|
PGDATAOLD=$PGDATA
|
|
fi
|
|
|
|
#
|
|
# Init DB: $PGDATA is empty.
|
|
# Upgrade DB: 1, has $PGDATA\PG_VERSION. 2, has pg old version directory with PG_VERSION inside.
|
|
#
|
|
if [ "$(ls -A $PGDATA)" ]; then
|
|
if [ ! -d $PGDATANEW ]; then
|
|
if [ ! -d $PGDATAOLD ] || [ ! -s $PGDATAOLD/PG_VERSION ]; then
|
|
echo "incorrect data: $PGDATAOLD, make sure $PGDATAOLD is not empty and with PG_VERSION inside."
|
|
exit 1
|
|
fi
|
|
initPG $PGDATANEW false
|
|
# because of the 'set -e', the upgrade failure will break execution.
|
|
./$CUR/upgrade.sh --old-bindir $PGBINOLD --old-datadir $PGDATAOLD --new-datadir $PGDATANEW
|
|
echo "remove the $PGDATAOLD after upgrade success."
|
|
if [ "$PGDATAOLD" = "$PGDATA" ]; then
|
|
find $PGDATA/* -prune ! -name pg${PG_VERSION_NEW} -exec rm -rf {} \;
|
|
else
|
|
rm -rf $PGDATAOLD
|
|
fi
|
|
else
|
|
echo "no need to upgrade postgres, launch it."
|
|
fi
|
|
else
|
|
initPG $PGDATANEW true
|
|
fi
|
|
|
|
POSTGRES_PARAMETER=''
|
|
file_env 'POSTGRES_MAX_CONNECTIONS' '1024'
|
|
# The max value of 'max_connections' is 262143
|
|
if [ $POSTGRES_MAX_CONNECTIONS -le 0 ] || [ $POSTGRES_MAX_CONNECTIONS -gt 262143 ]; then
|
|
POSTGRES_MAX_CONNECTIONS=262143
|
|
fi
|
|
|
|
POSTGRES_PARAMETER="${POSTGRES_PARAMETER} -c max_connections=${POSTGRES_MAX_CONNECTIONS}"
|
|
exec postgres -D $PGDATANEW $POSTGRES_PARAMETER |