From 31fdceb34fc108e662c687aa7c54cb20c7c4fb06 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 8 Oct 2025 19:39:26 +0200 Subject: [PATCH] Prepare migration to 17 -> 18 --- Dockerfile | 19 +++++++++---------- README.md | 4 ++-- build.sh | 2 +- migrate.sh | 4 ++-- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index b7c74be..c2f58fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,16 @@ +FROM ubuntu:noble AS build18 +RUN apt update && apt upgrade -y && apt install -y wget curl tar build-essential libreadline-dev zlib1g-dev flex bison libicu-dev pkg-config +RUN wget https://ftp.postgresql.org/pub/source/v18.0/postgresql-18.0.tar.gz -O pg18.tar.gz +RUN tar -xf pg18.tar.gz +RUN cd postgresql* && ./configure --prefix=/postgres/18 && make world-bin && make install + FROM ubuntu:noble AS build17 RUN apt update && apt upgrade -y && apt install -y wget curl tar build-essential libreadline-dev zlib1g-dev flex bison libicu-dev pkg-config - -RUN wget https://ftp.postgresql.org/pub/source/v17.2/postgresql-17.2.tar.gz -O pg17.tar.gz +RUN wget https://ftp.postgresql.org/pub/source/v17.6/postgresql-17.6.tar.gz -O pg17.tar.gz RUN tar -xf pg17.tar.gz RUN cd postgresql* && ./configure --prefix=/postgres/17 && make world-bin && make install -FROM ubuntu:noble AS build16 -RUN apt update && apt upgrade -y && apt install -y wget curl tar build-essential libreadline-dev zlib1g-dev flex bison libicu-dev pkg-config - -RUN wget https://ftp.postgresql.org/pub/source/v16.6/postgresql-16.6.tar.gz -O pg16.tar.gz -RUN tar -xf pg16.tar.gz -RUN cd postgresql* && ./configure --prefix=/postgres/16 && make world-bin && make install - FROM ubuntu:noble RUN apt update && apt install -y \ libicu74 \ @@ -27,8 +25,9 @@ ENV LANG=en_US.utf8 ENV POSTGRES_USER=postgres +COPY --from=build18 /postgres/18 /postgres/18 COPY --from=build17 /postgres/17 /postgres/17 -COPY --from=build16 /postgres/16 /postgres/16 + COPY migrate.sh /migrate.sh RUN chmod +x migrate.sh diff --git a/README.md b/README.md index c12163e..86aab08 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,10 @@ This repository will: Create an outdated database: ```bash mkdir test-db -docker run --rm --name testdb -u 1000 -e POSTGRES_PASSWORD=password -v $(pwd)/test-db:/var/lib/postgresql/data -it postgres:16 +docker run --rm --name testdb --env PGDATA=/var/lib/postgresql/data -u 1000 -e POSTGRES_PASSWORD=password -v $(pwd)/test-db:/var/lib/postgresql/data -it postgres:17 ``` Perform the migration (you need to replace `POSTGRES_USER` and `POSTGRES_PASSWORD` with the credentials of the root user of the database): ```bash -docker run -u 1000 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -v $(pwd)/test-db:/db --rm -it pierre42100/postgresmig:16to17 +docker run -u 1000 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -v $(pwd)/test-db:/db --rm -it pierre42100/postgresmig:17to18 ``` diff --git a/build.sh b/build.sh index 454ab9b..001795f 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,2 @@ #!/bin/bash -docker build . -t pierre42100/postgresmig:16to17 \ No newline at end of file +docker build . -t pierre42100/postgresmig:17to18 \ No newline at end of file diff --git a/migrate.sh b/migrate.sh index 9e94afd..f9d1bdf 100644 --- a/migrate.sh +++ b/migrate.sh @@ -17,12 +17,12 @@ cp -r "$DB_PATH" "$OLD_DB_PATH" # Initialize NEW database mkdir "$NEW_DB_PATH" -/postgres/17/bin/initdb -D "$NEW_DB_PATH" --username "$POSTGRES_USER" --pwfile=<(printf "%s\n" "$POSTGRES_PASSWORD") || exit 1 +/postgres/18/bin/initdb -D "$NEW_DB_PATH" --username "$POSTGRES_USER" --pwfile=<(printf "%s\n" "$POSTGRES_PASSWORD") || exit 1 # 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 +/postgres/18/bin/pg_upgrade -b /postgres/17/bin/ -d "$OLD_DB_PATH" -D "$NEW_DB_PATH" -U "$POSTGRES_USER" || exit 2 # Configure database server echo Configure database server