How to upgrade PostgreSQL database running as Docker container between major versions.
Procedure useful for migrating Nextcloud PostgreSQL 13 container database to PostgreSQL 15 database.
Naming convention:
nextcloud-postgres13 - container with PostgreSQL 13 database
nextcloud-postgres15 - container with PostgreSQL 15 database
Before performing migration start new container with PostgreSQL 15 database.
Following docker-compose YAML file can be used:
container_name: nextcloud-postgres15
hostname: nextcloud-postgres15
image: postgres:15-alpine
restart: always
volumes:
- /data/nextcloud-postgresql15-data:/var/lib/postgresql/data
environment:
- POSTGRES_PASSWORD=your_database_password
- POSTGRES_DB=nextcloud
- POSTGRES_USER=nextcloud
Dump data from PostgreSQL 13 database:
Inport data to new PostgreSQL 15 database:
After migration, check Nextcloud logs
Errors which can be found after upgrading PostgreSQL to version 15:
2022-12-20 21:06:19.959 UTC [29] FATAL: password authentication failed for user "nextcloud"
2022-12-20 21:06:19.959 UTC [29] DETAIL: User "nextcloud" does not have a valid SCRAM secret.
Connection matched pg_hba.conf line 100: "host all all all scram-sha-256"
Fix SCRAM secret after upgrading PostgreSQL to version 15:
rolname, rolpassword ~ '^SCRAM-SHA-256\$' AS has_upgraded
FROM pg_authid
WHERE rolcanlogin;
change PostgreSQL password