From 1e0d5cd9145de706ad7443a71f02080d72303e6d Mon Sep 17 00:00:00 2001 From: Hugo Lecuyer Date: Tue, 15 Oct 2024 10:43:57 +0200 Subject: [PATCH] feat(core): migration postgres 14 to 17 --- datawarehouse/Dockerfile | 6 ++-- deployment/MIGRATION.md | 71 ++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 1 - 3 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 deployment/MIGRATION.md diff --git a/datawarehouse/Dockerfile b/datawarehouse/Dockerfile index 2a53b5ad9..c0a96c1fa 100644 --- a/datawarehouse/Dockerfile +++ b/datawarehouse/Dockerfile @@ -1,4 +1,4 @@ -FROM postgres:14.9-bookworm +FROM postgres:17.0-bookworm ENV VIRTUAL_ENV /app/venv ENV PATH "${VIRTUAL_ENV}/bin:${PATH}" @@ -9,8 +9,8 @@ RUN localedef -i fr_FR -c -f UTF-8 -A /usr/share/locale/locale.alias fr_FR.UTF-8 RUN apt-get update \ && apt-get install -y --no-install-recommends \ - postgresql-14-postgis-3 \ - postgresql-plpython3-14 \ + postgresql-17-postgis-3 \ + postgresql-plpython3-17 \ python3-pip \ python3-venv \ && apt-get autoremove --purge -y \ diff --git a/deployment/MIGRATION.md b/deployment/MIGRATION.md new file mode 100644 index 000000000..21d6de3cf --- /dev/null +++ b/deployment/MIGRATION.md @@ -0,0 +1,71 @@ +Here is the corrected and formatted version of your migration process: +**The goal**: Migrate PostgreSQL from 14 to 17 + +### Steps: + +1. **Connect via SSH to the instance** +```bash +ssh root@{ip} +``` +2. **Install PostgreSQL 17** + ```bash + sudo apt install curl ca-certificates + sudo install -d /usr/share/postgresql-common/pgdg + sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc + + sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' + + sudo apt update + + sudo apt -y install postgresql + ``` + +3. **Create a backup of the current database after stoping other container | Stop all ** + ```bash + cd data-inclusion + docker compose stop + docker compose up datawarehouse -d + pg_dump -d 'postgresql://datainclusion:{password}@172.17.0.1:5432/datainclusion' -Fc -f migrate_14_to_17.dump + ``` + +4. **Import the dump locally** + Transfer the backup file to your local machine: + + ```bash + scp root@{ip}:/root/migrate_14_to_17.dump ~/data + ``` + +5. **Stop the instance** + Stop the running services using Docker Compose: + + ```bash + docker compose stop + ``` + +6. **Clean the data folder** + Remove all the existing data in the target database container: + + ```bash + docker compose run datawarehouse bash + rm -rf /var/lib/postgresql/data/* + ``` + +7. **Update the PostgreSQL version** + Deploy from pull request ?? + +8. **Access the new PostgreSQL container** + Enter the PostgreSQL container: + + ```bash + docker compose exec datawarehouse bash + ``` + +8. **Run the migration** + Restore the backup to the new PostgreSQL version: + + ```bash + pg_restore --no-owner -Fc /var/lib/postgresql/migrate/migrate_14_to_17.dump -d 'postgresql://datainclusion:{password}@172.17.0.1:5432/datainclusion' -j 8 -v + ``` + +10. **Deploy the updated environment** + After the migration, deploy the necessary changes. \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 5ed4fffa2..1eb3a0f5a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -137,7 +137,6 @@ services: - minio target-db: - image: data-inclusion/datawarehouse build: datawarehouse restart: no command: -c fsync=off -c full_page_writes=off -c synchronous_commit=off -c log_statement=all