Upgrade major version change

This commit is contained in:
Alexandre
2025-02-15 11:15:34 +01:00
parent 7d48f8b9cc
commit dba895757f

View File

@@ -61,7 +61,7 @@ bashio::log.info "Waiting for PostgreSQL to start..."
( bashio::net.wait_for 5432 localhost 900
###############################
# PostgreSQL Major Version Upgrade Check #
# PostgreSQL Major Version Upgrade #
###############################
# Read the previous PostgreSQL version from file
@@ -70,10 +70,40 @@ OLD_PG_VERSION=$(cat "$PG_VERSION_FILE" 2>/dev/null || echo "")
if [ "$OLD_PG_VERSION" != "$PG_MAJOR_VERSION" ]; then
bashio::log.warning "PostgreSQL major version changed ($OLD_PG_VERSION$PG_MAJOR_VERSION). Running upgrade..."
OLD_BIN_DIR="/usr/lib/postgresql/$OLD_PG_VERSION/bin"
NEW_BIN_DIR="/usr/lib/postgresql/$PG_MAJOR_VERSION/bin"
# Check if the old PostgreSQL binaries exist
if [ ! -d "$OLD_BIN_DIR" ]; then
bashio::log.warning "Old PostgreSQL binaries ($OLD_PG_VERSION) not found! Downloading..."
# Determine the package URL (adjust this as needed for your PostgreSQL distribution)
PG_DOWNLOAD_URL="https://ftp.postgresql.org/pub/source/v$OLD_PG_VERSION/postgresql-$OLD_PG_VERSION.tar.gz"
# Create a temporary directory for the download
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR" || exit 1
# Download and extract PostgreSQL source
wget "$PG_DOWNLOAD_URL" -O postgresql.tar.gz
tar -xzf postgresql.tar.gz
# Build only the necessary binaries
cd "postgresql-$OLD_PG_VERSION" || exit 1
./configure --prefix="$OLD_BIN_DIR"
make -j$(nproc)
make install
# Clean up
cd /config || exit 1
rm -rf "$TMP_DIR"
fi
# Run pg_upgrade with the correct paths
pg_upgrade --old-datadir="$PGDATA" \
--new-datadir="$PGDATA-new" \
--old-bindir="/usr/lib/postgresql/$OLD_PG_VERSION/bin" \
--new-bindir="/usr/lib/postgresql/$PG_MAJOR_VERSION/bin"
--old-bindir="$OLD_BIN_DIR" \
--new-bindir="$NEW_BIN_DIR"
# Replace old data directory with upgraded one
mv "$PGDATA" "$PGDATA-old"