Changing Database URL

How does one migrate database URLs? Specifically, I have a pgsql instance at at say but that server was replaced with a new one at I restored a pg_dump of the nextcloud, so I know that the data is in the database.

I then tried changing the url in config/config.php but get error 504.

What can I do to make this migration possible? I’ve tried using

but the tool cannot convert from postgres → postgres.

Start troubleshooting from the basics. From your description it sounds NC and DB are running on different machines - lot of things can go wrong e,g. firewall. Check if you manually can access the database from your NC system using the NC credentials - once this works double check, database, user and password you are using in NC…

Yes, they are on different machines.

My other services that access Postgres had no issue. They can read from the database, insert, etc.

The NC user and database were restored and I confirmed that I can connect via psql.

I’m wondering if there is some command I need to run to update NC to use the new database URL?

I didn’t do any migration so far but according to the following threads there is nothing special, just adopt the config.php. maybe you missed to stop and restart the system when changing the config.php file?

I’ve figured it out from the second link.

The steps are:

  1. Enable maintenance mode sudo -u www-data PHP_MEMORY_LIMIT=1G php /var/www/html/occ maintenance:mode --on (note that I needed the memory limit or else OCC won’t run)
  2. pg_dumpall
  3. Restore the dump
  4. Edit the config/config.php, separating the dbhost and dbport string.


'dbhost' => 'remotehost:port', 
'dbport' => ''


'dbhost' => 'remotehost', 
'dbport' => 'port'
  1. Disable maintenance mode: sudo -u www-data PHP_MEMORY_LIMIT=1G php /var/www/html/occ maintenance:mode --off
1 Like