Nextcloud postgres update fails

Hey, I’ve been using the official Nextcloud app on TrueNAS scale for a while now and it’s been through the docker migration already.
It’s currently still using postgres version 13 and I wanted to upgrade to version 17 recently. Unfortunately the database upgrade is failing with FATAL: role "postgres" does not exist.
I also noticed that the regular postgres container is complaining about this with postgres 13 before the upgrade:

2025-10-09 11:18:02.971175+00:002025-10-09 11:18:02.971 UTC [27] FATAL:  role "postgres" does not exist
2025-10-09 11:18:33.061864+00:002025-10-09 11:18:33.061 UTC [43] FATAL:  role "postgres" does not exist
2025-10-09 11:19:03.149462+00:002025-10-09 11:19:03.149 UTC [52] FATAL:  role "postgres" does not exist
2025-10-09 11:19:33.230057+00:002025-10-09 11:19:33.229 UTC [60] FATAL:  role "postgres" does not exist
2025-10-09 11:20:03.303558+00:002025-10-09 11:20:03.303 UTC [70] FATAL:  role "postgres" does not exist
2025-10-09 11:20:33.406030+00:002025-10-09 11:20:33.405 UTC [78] FATAL:  role "postgres" does not exist
2025-10-09 11:21:03.470520+00:002025-10-09 11:21:03.470 UTC [87] FATAL:  role "postgres" does not exist

I assume something went wrong at some point and my database configuration doesn’t match my nextcloud configuration? Interestingly everything appears to be working normally, even with those errors in the log.

Any ideas would be greatly appreciated! Would love to upgrade to postgres 17 and resolve those fatals in the logs.

I was able to solve this issue, but I’m not sure what caused it in the first place.
I started by opening a shell in the postgres container and connected to the database using the oc_admin role. Then I listed all roles using the \du command.

$ psql -h localhost -U oc_admin -d nextcloud
psql (17.6 (Debian 17.6-2.pgdg12+1))
Type "help" for help.

nextcloud=> \du
                             List of roles
 Role name |                         Attributes                         
-----------+------------------------------------------------------------
 oc_admin  | Create DB
 ��-���    | Superuser, Create role, Create DB, Replication, Bypass RLS

This is where I noticed that my postgres superuser had a gibberish, corrupted looking name. I went back to my oldest snapshot and this name was still looking corrupted. Nothing else in the database appears to be corrupted though and my nextcloud instance is running without issues.
I was still able to login as this corrupted user (which for some reason had a matching database), so I decided to create a temporary superuser role and simply rename this corrupted role to “postgres”.
Now the migration to postgres 17 worked without issues and the log spam is gone.

I’m still not sure what caused this, any ideas would be greatly appreciated.

Tried that command. User oc_admin does not exist.

I logged in as the current superuser:

psql -h localhost -U "��-���"

Then created a new temporary superuser role:

CREATE ROLE temp WITH SUPERUSER INHERIT CREATEROLE CREATEDB LOGIN REPLICATION BYPASSRLS;

After that I logged in as this new temp role using the database of the “��-���” user:

psql -h localhost -U temp -d "��-���"

Then I simply renamed the “��-���” user to “postgres”:

ALTER ROLE "��-���" RENAME TO "postgres";

The migration worked for me after the rename. You can also delete the temp role now.

Check your nextcloud config.php for

'dbuser' => 'oc_admin'

Yours might be called differently.

Hi,
thanks. That was much easier than feared.
Works now and update worked.
CU
Jens

1 Like

Some days all the needed synapses don’t fire. All I had to do was select version 17 of postgresql and update that. Then the rest worked.

My error in the logs was:
connection to server on socket "/var/run/postgresql/.s.PGSQL.50432" failed: FATAL: role "nextcloud" does not exist

It worked for me to rename the gibberish name to “nextcloud” (not “postgres”)

I also did this, but I’m not sure if it was even required.

ALTER USER nextcloud WITH PASSWORD '????????';

I couldn’t get a shell using the web UI so I had to log on to the TrueNAS server, start the nextcloud app with the old DB version, then stop the nextcloud container with docker, and connect to the DB container.

This is a really strange, almost comical error, but sad if many people less experienced with docker will be left in this state.