Skip to content

Commit

Permalink
feat(core): migration postgres 14 to 17
Browse files Browse the repository at this point in the history
  • Loading branch information
hlecuyer committed Oct 15, 2024
1 parent 4560db2 commit e238119
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
6 changes: 3 additions & 3 deletions datawarehouse/Dockerfile
Original file line number Diff line number Diff line change
@@ -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}"
Expand All @@ -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 \
Expand Down
68 changes: 68 additions & 0 deletions deployment/MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
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**
```bash
pg_dump -d 'postgresql://datainclusion:{password}@172.17.0.1:5432/datainclusion' -Fc -f migrate_14_to_17.sql
```

4. **Import the dump locally**
Transfer the backup file to your local machine:

```bash
scp root@{ip}:/root/migrate_14_to_17.sql ~/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 target-db bash
rm -rf /var/lib/postgresql/data/*
```

7. **Update the PostgreSQL version**
Change the version in your Docker configuration (e.g., in the `docker-compose.yml` file).

8. **Access the new PostgreSQL container**
Enter the PostgreSQL container:

```bash
docker compose exec datawarehouse bash
```

9. **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.sql -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.
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ services:
- minio

target-db:
image: data-inclusion/datawarehouse
build: datawarehouse
restart: on-failure
command: -c fsync=off -c full_page_writes=off -c synchronous_commit=off -c log_statement=all
Expand Down

0 comments on commit e238119

Please sign in to comment.