Database resets every time I re-open the workspace

So we have a Python/Flask/React boilerplate that we maintain, it’s completely integrated with Gitpod with a Postgress database, here is the repository.

The docker file installs Postgres and the gitpod.yml creates a new database.

My problem:
Every time the workspace shuts down it seems to delete the data from the database.

I also have another boilerplate with Flask/Python and MySQL but the data remains after reboot (ideal).

How can I avoid data reset? Moving the database creation from the gitpod.yml to the docker file?

Here is the gitpod.yml:

    - init: >
        (cp -n .env.example .env || true) && 
        echo "" >> .env && echo "BACKEND_URL=https://3001-${GITPOD_WORKSPACE_URL:8}" >> .env && 
        pipenv install &&
        psql -U gitpod -c 'CREATE DATABASE example;' &&
        psql -U gitpod -c 'CREATE EXTENSION unaccent;' -d example &&
        pipenv run init && 
        pipenv run migrate && 
        pipenv run upgrade &&
        python docs/assets/ back
    - command: >
        npm install &&
        python docs/assets/ front
      openMode: split-right

Hi @alesanchezr! :wave:

Currently, Gitpod only backs up the /workspace directory of your workspaces between restarts. This means that any changes made outside that directory (e.g. in /tmp, but also in /home/gitpod) are not saved between restarts.

That’s why, for the official Postgres image gitpod/workspace-postgres, we’ve set PGDATA to be inside /workspace:

I see that in your setup, you set PGDATA inside /home/gitpod, which means that DB data unfortunately won’t be persisted over workspace restarts:

But I see several options here to guarantee that your DB data gets persisted across workspace restarts:

  1. Enabling “Full Workspace Backup” for your account: Only backing up the /workspace directory isn’t ideal, and we’d like to remove this limitation soon, which is why we’ve implemented a new backup system that saves the entire file system of your workspace, not just the /workspace directory (i.e. changes in HOME will start being persisted too). That feature still has a few minor performance issues, so it’s not generally available yet, but we can enable it on your account if you’re interested to try it. :slight_smile:

  2. Changing PGDATA in your Dockerfile to be within /workspace, just like in our Postgres image

  3. Replacing your custom Postgres setup with Gitpod’s own, by basing your Dockerfile on gitpod/workspace-postgres instead of gitpod/workspace-full

Let me know which solution you’d prefer! :raised_hands: Happy to help.

1 Like

OMG@jan your explanation is amazing, knowing how Gitpod stores the data is very useful from now on. Thank you!!

I fixed the issue in 2 minutes by using your option number 3 :smile:

I’m thrilled with Gitpod success and you guys can always count with me and 4geeks.