WIP migration guide

This commit is contained in:
Pierre HUBERT 2024-12-06 11:55:41 +01:00
parent 2ded4f6ed9
commit a69ac9bc50
2 changed files with 20 additions and 17 deletions

View File

@ -9,5 +9,5 @@ docker run --rm --name testdb -u 1000 -e POSTGRES_PASSWORD=password -v $(pwd)/te
Perform the migration:
```bash
./build.sh && docker run -u 1000 -v $(pwd)/test-db:/db --rm -it pierre42100/postgresmig:16to17
./build.sh && docker run -u 1000 -e POSTGRES_PASSWORD=password -v $(pwd)/test-db:/db --rm -it pierre42100/postgresmig:16to17
```

View File

@ -3,26 +3,29 @@ echo Migrate PostgreSQL version
DB_PATH=/db
OLD_DB_PATH=/tmp/old_db
NEW_DB_PATH=/tmp/new_db
DB_PWD_FILE=/tmp/db_pwd_file
# Handle password
if [ -z "$POSTGRES_PASSWORD" ] || [ "$POSTGRES_PASSWORD" == " " ];
then
echo "Please specify database password in POSTGRES_PASSWORD env variable!"
exit 1;
fi
echo "$POSTGRES_PASSWORD" > "$DB_PWD_FILE"
truncate -s -1 "$DB_PWD_FILE"
# Run database on a COPY of the database
cp -r "$DB_PATH" "$OLD_DB_PATH"
# Start the database in the background
/postgres/16/bin/postgres -D /tmp/old_db/ &
while true;
do
echo Waiting for database...
if echo "\q" | /postgres/16/bin/psql -U "$POSTGRES_USER";
then
break
fi
done
# Perform dump
# Initialize NEW database
mkdir "$NEW_DB_PATH"
/postgres/17/bin/initdb -D "$NEW_DB_PATH" --username "$POSTGRES_USER" --pwfile="$DB_PWD_FILE" || exit 1
# Stop database
#pkill postgres
# Perform migration
cd /tmp
/postgres/17/bin/pg_upgrade -b /postgres/16/bin/ -d "$OLD_DB_PATH" -D "$NEW_DB_PATH" -U "$POSTGRES_USER" || exit 2
bash
# TODO: replace database