WIP migration guide
This commit is contained in:
parent
2ded4f6ed9
commit
a69ac9bc50
@ -9,5 +9,5 @@ docker run --rm --name testdb -u 1000 -e POSTGRES_PASSWORD=password -v $(pwd)/te
|
|||||||
|
|
||||||
Perform the migration:
|
Perform the migration:
|
||||||
```bash
|
```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
|
||||||
```
|
```
|
35
migrate.sh
35
migrate.sh
@ -3,26 +3,29 @@ echo Migrate PostgreSQL version
|
|||||||
|
|
||||||
DB_PATH=/db
|
DB_PATH=/db
|
||||||
OLD_DB_PATH=/tmp/old_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
|
# Run database on a COPY of the database
|
||||||
cp -r "$DB_PATH" "$OLD_DB_PATH"
|
cp -r "$DB_PATH" "$OLD_DB_PATH"
|
||||||
|
|
||||||
# Start the database in the background
|
# Initialize NEW database
|
||||||
/postgres/16/bin/postgres -D /tmp/old_db/ &
|
mkdir "$NEW_DB_PATH"
|
||||||
|
/postgres/17/bin/initdb -D "$NEW_DB_PATH" --username "$POSTGRES_USER" --pwfile="$DB_PWD_FILE" || exit 1
|
||||||
while true;
|
|
||||||
do
|
|
||||||
echo Waiting for database...
|
|
||||||
if echo "\q" | /postgres/16/bin/psql -U "$POSTGRES_USER";
|
|
||||||
then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
# Perform dump
|
|
||||||
|
|
||||||
|
|
||||||
# Stop database
|
# Perform migration
|
||||||
#pkill postgres
|
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
|
Loading…
Reference in New Issue
Block a user