Upgrade postgres database failure

On Docker, I currently use postgres:13-alpine as my database for nextcloud:apache.

I want to upgrade to postgres:15-alpine.

Using official instructions, I dumped the db from postgres 13

PGPASSWORD="xxx" pg_dump nextcloud -U oc_myname -f /dump/nextcloud.dump

and restored it on postgres 15 with the official instructions

PGPASSWORD="xxx" psql -U oc_myname -d template1 -c "DROP DATABASE \"nextcloud\";"
PGPASSWORD="xxx" psql -U oc_myname -d template1 -c "CREATE DATABASE \"nextcloud\";"
PGPASSWORD="xxx" psql -U oc_myname -d nextcloud -f /dump/nextcloud.dump

But when I start Nextcloud on the postgres 15 database, it says 500 Internal Error, and that’s it.

I have also tried to backup with

pg_dumpall -U oc_myname > /dump/nextcloud.dumpall

and restore with the same process, but same result.

I have 2 questions:

  1. Is the official guide outdated? If yes, do you know of a better way to upgrade a Docker database?
  2. If I start a new empty postgres 15 container, and use Nextcloud to scan and add all files to the database, will I lose any information, e.g. file/activity history, app settings?

It turns out that the user is not initialized properly with postgres:13. The database user is oc_nextcloud regardless of the environment variables.

The official procedure works as long as the oc_nextcloud user is created and owns the database nextcloud. I made it work by

  1. changing the POSTGRES_USER variable to oc_nextcloud (I guess replacing oc_nextcloud to something else in the dump would work too) both in the docker-compose.yml file and nextcloud’s /var/www/html/config/config.php at dbuser
  2. restoring the dump with username oc_nextcloud