Rename database and prefixes

I migrated from owncloud a while ago, and now I need to migrate my Nextcloud instance to a new server. I thought I would use the opportunity and rename my database, which is still name owncloud, and oc_ being the prefix.

Can I simply rename to database to Nexcloud, change the prefix to nc_, and make according changes in config.php? Or would that create problems further down the road?

Nextcloud by default still keeps oc_ prefix and I highly recommended to not change something about that. All existing tables would need to be renamed including possibly some references within.

If you move to new server, you anyway need to mysqldump the ownCloud database and you can import it on the new server providing a new database named nextcloud. That should be painless with something like:
mysqldump owncloud > owncloud_dump.sql
mysql nextcloud < owncloud_dump.sql

Normally, the prefix is a variable taken from the config.php. If there are problems, I would rather guess it is from some apps that don’t implement this properly. The table names are not visible to users, so why change it and take the risk?

I created a script, that removes the prefix here:

In postgres, I did it this way:
Inspired by this SO.

select 'ALTER TABLE ' || table_name ||  ' RENAME TO ' || substr(table_name, 4) ||';' from information_schema.tables where table_name like 'oc_%';

And then I copied/paste these statements.