If You Are Having Trouble Restoring NextCloud Docker PostgreSQL DB

Support intro

Sorry to hear you’re facing problems. :slightly_frowning_face:

The community help forum (help.nextcloud.com) is for home and non-enterprise users. Support is provided by other community members on a best effort / “as available” basis. All of those responding are volunteering their time to help you.

If you’re using Nextcloud in a business/critical setting, paid and SLA-based support services can be accessed via portal.nextcloud.com where Nextcloud engineers can help ensure your business keeps running smoothly.

Getting help

In order to help you as efficiently (and quickly!) as possible, please fill in as much of the below requested information as you can.

Before clicking submit: Please check if your query is already addressed via the following resources:

(Utilizing these existing resources is typically faster. It also helps reduce the load on our generous volunteers while elevating the signal to noise ratio of the forums otherwise arising from the same queries being posted repeatedly).

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • 31.0.7
  • Operating system and version (e.g., Ubuntu 24.04):
    • Ubuntu 24.04
  • Web server and version (e.g, Apache 2.4.25):
    • Apache, version in latest Docker Image
  • Reverse proxy and version _(e.g. nginx 1.27.2)
    • NGINX
  • PHP version (e.g, 8.3):
    • Unknown
  • Is this the first time you’ve seen this error? (Yes / No):
    • No
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)

Summary of the issue you are facing:

I have already solved the problem, I just wanted to share the steps I took to successfully restore a database backup to a new PostgreSQL server.

I encountered “must be able to set role as oc_admin” errors among others during the restore step.

Steps to replicate it (hint: details matter!):

  1. Backup NC DB from source using pg_dump.
  2. Follow NC website instructions to create new DB on the new server.
  3. Attempt to restore backup to new server.

My experience was that the instructions I found for creating a new nextcloud database on a new PostgreSQL server were insufficient as they did not cover setting up all of the required user accounts, granting schema permissions and even the need to give the nextcloud database user role access to assign the role of oc_admin.

In my setup, I had two accounts on the original PostgreSQL docker container for NextCloud. One (nextcloud_user) is referenced within the original docker compose under the db section. The other, oc_admin, is referenced in config.php. I am uncertain as to why this is set up this way.

In my scenario, the following steps created the new DB with all required schema permissions and roles:

psql -U postgres
CREATE DATABASE nextcloud TEMPLATE template0 ENCODING ‘UTF8’;
CREATE USER nextcloud_user WITH PASSWORD 'changeme';
CREATE USER oc_admin WITH PASSWORD ‘changeme’;
GRANT ALL PRIVILEGES ON DATABASE nextcloud TO nextcloud_user;
ALTER DATABASE nextcloud OWNER to nextcloud_user;
GRANT CONNECT ON DATABASE nextcloud TO oc_admin;
GRANT CREATE ON SCHEMA public TO oc_admin;
GRANT oc_admin TO nextcloud_user WITH ADMIN OPTION;
\q

psql -U nextcloud_user -d nextcloud
GRANT CREATE ON SCHEMA public TO oc_admin;
GRANT ALL PRIVILEGES ON SCHEMA public TO nextcloud_user;

Once I followed this procedure I was able to restore my backup to the new server successfully. From there I made the required changes to my docker compose file and my config.php to point to the new server, ran docker compose up -d and my deployment was up and running.

I wanted to share this for reference in case it may help someone else avoid spending hours sorting this out. For anyone who is unfamiliar with database administration, I suggest that you google each of the commands above to fully understand what they do before running them.

If anyone sees a mistake I made, I would be happy to update the instructions above and also to tweak my deployment. :slight_smile:

  • SCH00N3R
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.