Postgres container crashes with `database files are incompatible with server` after container's image has been updated to the latest one
Additionally don't forget to clear the old pgdata
volume:
docker volume ls
and then docker volume rm <volume-name>
Otherwise your error will still remain.
See https://github.com/ckan/ckan/issues/4164#issuecomment-388069003
I got this error because i was always using the latest version of postgres by not defining a tag at the end. Then the latest version switched to 13 and the data was not compatible anymore. Maybe just adding a version at the end might help too. -> postgres:12
postgres:
image: postgres:12
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
ports:
- "5432:5432"
volumes:
- db_data:/var/lib/postgresql/data
You are on time to save it, but you need to rollback to previous version, then:
docker exec -it <postgres-container-id> pg_dump db_name > local.dump.sql
Then, after checking that the dump is OK, empty the volume of the database, upgrade postgres and restore de dump:
https://www.postgresql.org/docs/9.1/static/backup-dump.html