2017-06-23 04:54:27 +02:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
set -e
|
|
|
|
|
|
2021-05-20 10:25:50 +02:00
|
|
|
|
source $PWD/initdb.sh
|
2017-06-23 04:54:27 +02:00
|
|
|
|
|
2021-05-20 10:25:50 +02:00
|
|
|
|
CUR=$PWD
|
|
|
|
|
PG_VERSION_OLD=$1
|
|
|
|
|
PG_VERSION_NEW=$2
|
2017-06-23 04:54:27 +02:00
|
|
|
|
|
2022-09-21 11:59:25 +02:00
|
|
|
|
PGBINOLD="/usr/pgsql/${PG_VERSION_OLD}/bin"
|
2017-06-23 04:54:27 +02:00
|
|
|
|
|
2021-05-20 10:25:50 +02:00
|
|
|
|
PGDATAOLD=${PGDATA}/pg${PG_VERSION_OLD}
|
|
|
|
|
PGDATANEW=${PGDATA}/pg${PG_VERSION_NEW}
|
2022-09-21 11:59:25 +02:00
|
|
|
|
|
|
|
|
|
# We should block the upgrade path from 9.6 directly.
|
2021-05-20 10:25:50 +02:00
|
|
|
|
if [ -s $PGDATA/PG_VERSION ]; then
|
2023-05-05 04:32:39 +02:00
|
|
|
|
echo "Upgrading from PostgreSQL 9.6 to PostgreSQL $PG_VERSION_NEW is not supported in the current Harbor release."
|
2022-09-21 11:59:25 +02:00
|
|
|
|
echo "You should upgrade to previous Harbor firstly, then upgrade to current release."
|
|
|
|
|
exit 1
|
2021-05-20 10:25:50 +02:00
|
|
|
|
fi
|
2017-06-23 04:54:27 +02:00
|
|
|
|
|
2022-09-21 11:59:25 +02:00
|
|
|
|
# Upgrade DB: 1. PG_NEW\PG_VERSION file doesn’t exist and pg_old_parameter is not nil and PG_OLD\PG_VERSION file exist.
|
|
|
|
|
# For example: ["13", "14"]
|
|
|
|
|
# In harbor v2.8, Harbor 2.7 was installed before, db version was 13,
|
|
|
|
|
# It needs to upgrade the database from pg 13 to pg 14,
|
|
|
|
|
# ["13", "14"] means support for upgrading from pg 13 to pg 14.
|
|
|
|
|
# Init DB: 1. PG_NEW\PG_VERSION file doesn’t exist and pg_old_parameter is not nil and PG_OLD\PG_VERSION file doesn’t exist.
|
|
|
|
|
# For example: ["13", "14"]
|
|
|
|
|
# In harbor v2.8, the first time installation, it needs to init the db for pg 14,
|
|
|
|
|
# ["13", "14"] means support for upgrading from pg 13 to pg 14.
|
|
|
|
|
# 2. PG_NEW\PG_VERSION file doesn’t exist and pg_old_parameter is nil.
|
|
|
|
|
# For example: ["", "14"]
|
|
|
|
|
# In harbor v2.8, the first time installation, it needs to init the db for pg 14,
|
|
|
|
|
# ["", "14"] means db upgrade is not supported.
|
|
|
|
|
if [ ! -s $PGDATANEW/PG_VERSION ]; then
|
|
|
|
|
if [ ! -z $PG_VERSION_OLD ] && [ -s $PGDATAOLD/PG_VERSION ]; then
|
|
|
|
|
echo "upgrade DB from $PG_VERSION_OLD to $PG_VERSION_NEW"
|
2021-05-20 10:25:50 +02:00
|
|
|
|
initPG $PGDATANEW false
|
2021-05-21 07:53:39 +02:00
|
|
|
|
set +e
|
2021-06-01 09:59:41 +02:00
|
|
|
|
# In some cases, like helm upgrade, the postgresql may not quit cleanly.
|
|
|
|
|
# Use start & stop to clean the unexpected status. Error:
|
|
|
|
|
# There seems to be a postmaster servicing the new cluster.
|
|
|
|
|
# Please shutdown that postmaster and try again.
|
|
|
|
|
# Failure, exiting
|
2021-06-08 08:41:12 +02:00
|
|
|
|
$PGBINOLD/pg_ctl -D "$PGDATAOLD" -w -o "-p 5433" start
|
2021-06-01 09:59:41 +02:00
|
|
|
|
$PGBINOLD/pg_ctl -D "$PGDATAOLD" -m fast -w stop
|
2021-05-20 10:25:50 +02:00
|
|
|
|
./$CUR/upgrade.sh --old-bindir $PGBINOLD --old-datadir $PGDATAOLD --new-datadir $PGDATANEW
|
2021-06-01 09:59:41 +02:00
|
|
|
|
# it needs to clean the $PGDATANEW on upgrade failure
|
2021-05-21 07:53:39 +02:00
|
|
|
|
if [ $? -ne 0 ]; then
|
2022-09-21 11:59:25 +02:00
|
|
|
|
echo "remove the $PGDATANEW after fail to upgrade."
|
2021-05-21 07:53:39 +02:00
|
|
|
|
rm -rf $PGDATANEW
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
set -e
|
2021-05-20 10:25:50 +02:00
|
|
|
|
echo "remove the $PGDATAOLD after upgrade success."
|
2022-09-21 11:59:25 +02:00
|
|
|
|
rm -rf $PGDATAOLD
|
2019-07-30 07:04:28 +02:00
|
|
|
|
else
|
2022-09-21 11:59:25 +02:00
|
|
|
|
echo "init DB, DB version:$PG_VERSION_NEW"
|
2023-05-05 04:32:39 +02:00
|
|
|
|
initPG $PGDATANEW true
|
2019-07-30 07:04:28 +02:00
|
|
|
|
fi
|
2017-06-23 04:54:27 +02:00
|
|
|
|
fi
|
2019-07-30 07:04:28 +02:00
|
|
|
|
|
2020-07-14 09:33:01 +02:00
|
|
|
|
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}"
|
2021-06-08 08:41:12 +02:00
|
|
|
|
exec postgres -D $PGDATANEW $POSTGRES_PARAMETER
|