Sometimes, due to connectivity issues (or even NextCloud bugs), files may end up in a locked state on the server. This means they can no longer be modified in any way, not even deleted.

Start by making a backup of the files in question (check that they are in usable state beforehand), then continue by placing the server in maintenance mode:
sudo -u USERNAME php occ maintenance:mode --on
Now proceed to clean up the oc_file_locks table in the database of any records of locked files with:
mysql -u <mysql_user> -p -D <nc_database_name> -e "DELETE FROM oc_file_locks WHERE 1"
Ensure that the correct MySQL username/password combination and database name are entered and that the necessary permissions are met.
You can also run the query in interactive mode (such as in a mysql prompt or via phpMyAdmin), if that’s more comfortable.

When done turn off maintenance:
sudo -u USERNAME php occ maintenance:mode --off

If you notice anything out place, perform a bit of maintenance with:
sudo -u USERNAME php occ files:scan --all
sudo -u USERNAME php occ files:cleanup

Finish things off by waiting for the client(s) to sync and then checking if the previously locked files are in order (and restore them from the backup if needed).

PS: Replace USERNAME with the correct username that the NextCloud instance runs under.

More info about file locks (and advanced configuration):


  1. Clean up the oc_file_locks table in the database of any records
    Whats that mean?

    On this page it is actually explained only that you need to enter the maintenance mode


Leave a Reply