PostgreSQL upgrade

For development setups and most of production ones too, the PostgreSQL database run through Docker and its data is stored through a Docker volume. To avoid any data loss, we strongly advice to save a copy of the volume before continuing with the following instructions. By default the volume is located at /var/lib/docker/volumes/callico_database/ and requires a privileged access (root).

Upgrade PostgreSQL data from version 13 to 17

We recommend performing the update using pg_dump, as it simplifies handling multiple major PostgreSQL updates.

  1. Make sure you ran all the latest migrations and checked out to the new version in docker-compose.yml

  2. Back up the existing data using pg_dump:

    docker run --rm --name=old-database --env-file=docker.env -v callico_database:/var/lib/postgresql/data -p 127.0.0.1:5432:5432 postgres:13-alpine
    docker exec old-database pg_dump -U callico -d callico > dump.sql

    There should be no error and the size of dump.sql should be approximately the size of the volume.

  3. Trash the previously used volume:

    docker kill old-database
    docker volume rm callico_database

    You will need to kill all database access first (e.g. Ctrl-C in the DB shell). In case docker complains about a container using the volume, you may also have to delete the container first:

    docker rm <container_id>
  4. You can then run the up-to-date PostgreSQL via docker-compose.yml, and restore the data:

    docker exec callico-database postgres -V # Should return "postgres (PostgreSQL) 17.x"
    docker compose up postgres
    PGPASSWORD=callicopwd psql --user=callico --host=localhost -d callico  < dump.sql
  5. Check the application runs as expected by starting a development server and running tests (all your data should be there).

  6. Cleanup the local file used for the dump:

    rm dump.sql