File is locked - how to unlock

You can’t access files because they are locked and you find such errors in your logfile:

{"reqId":"0DijSqEkfOg2iyh9VD8J","remoteAddr":"xx.xx.xx.xx","app":"webdav","message":"Exception: {\"Message\":\"HTTP\\\/1.1 423 \\\"path\\\/file.extension\\\" is locked\",\"Exception\":\"OCA\\\\DAV\\\\Connector\\\\Sabre\\\\Exception\\\\FileLocked\",\"Code\":0,\"Trace\":\"#0

Manually disable locking state:

  • put Nextcloud in maintenance mode: edit config/config.php and change this line:
    'maintenance' => true,
  • Empty table oc_file_locks: Use tools such as phpmyadmin or connect directly to your database and run (the default table prefix is oc_, this prefix can be different or even empty):
    DELETE FROM oc_file_locks WHERE 1
  • disable maintenance mode (undo first step).
  • Make sure your cron-jobs run properly (you admin page tells you when cron ran the last time):

Permanent solution (if it happens regularly)

  • on your own server: Use redis for this feature. It is faster and so far no problems have been reported. You can follow the instructions for memory-caching in the docs:
  • Shared hosting (others who can’t install redis): You can disable the file locking, edit your configuration file config/config.php:
    'filelocking.enabled' => false,
    However, disabling is not a good solution. You can run into problems when several processes try to write to a file (especially online editors in the web-interface). In single-user and single-client environments, it’s probably less of a problem.
File lock issue?
Unable to delete Files/Folders
Not able to delete one file
Cant Delete Files or Folders anymore
Not able to open txt files
Fil is locked and can't be synchronised? How to fix?
"occ file:scan --all -v" terminates with errorr
Locked files - how to unlock?
Can not remove the folders
Gesperrte Dateien entsperren für Anfänger
File Upload Error
External Storage Performance | occ files:scan --all
File locked by server, unresolvable with regular approaches
Nextcloud and a supporter account / view?
[SOLVED] Can't modify/delete files with "file locked" error
Files:scan --all create several exceptions
Files:scan user -- exception while scanning: "files" is locked
Erreur à la suppression de fichiers
Error 500 - NC - on page Settings and App Store
Problème création fichiers ou effacement
Possible reason why duplicate folders are automatically created
Es ist nicht möglich, mehr als 1 Datei gleichzeitig endgültig zu löschen
Cannot Delete Files - External Storage
File locked: How to resolve mysql nc_file_locks entrys
Nextcloud constantly accessing mariadb, log is blowing up
Can not unlock files in Database 18.0.9, postresql 10.14
Поврежденные файлы или что это?
How to resolve server replied "423 Locked" to "PUT https://
Fehlermeldung "Server hat 423 locked
Server answer "423 locked"
[Problem] Issue creating some folders
High Load on Postgres Database
Exception during scan
Exception during scan
Nextcloud Docker: Locked files prevent scanning
Samba mounts and File Locked error
Sync with windows client fails with shared files
Löschen von blockierten Ordnern
Nextcloud 11 : Uploading big file
QuiteRSS File locked after sync
Big file is locked after upload, no upload, redis used, update to 12.0.1
Error Deleting File "xxxxx"
Where are my tables?
NextcloudPi stops responding when using Nextcloud Win7 x64 client
Cryptomator Sync over WebDav has one locked file preventing complete sync
No connection to server with a new android phone
SMB external storage shows no files
'Locked file' error
Cannot delete own files
Next cloud Server and Desktop some file not sync
Sync client cancelling operations when trying to sync a folder
Freigegebene Dateien können nicht gelöscht werden
File is locked, cannot move a file
Welche Bedeutung haben die teilweise sehr hohen Zahlenwerte in der Spalte "lock" in der oc_file_locks Datenbanktabelle?
Multiples files locked - reccurent problem
Error when deleting file or folder

I have this problem. However, the manual solution above didn’t fix it. When I was in mysql to delete the locks, it did mention 17 rows affected. Now it says none, so it seems like it did delete locks. My Nextcloud cron jobs do still run properly, as indicated in the admin page. My file is still locked, though. I am using redis for data caching–not sure if that makes a difference.

Exception: {“Message”:“HTTP/1.1 423 “myfile.file” is locked”,“Exception”:“OCA\DAV\Connector\Sabre\Exception\FileLocked”,“Code”:0,“Trace”:"#0 /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Tree.php(179): OCA\DAV\Connector\Sabre\File->delete()\n#1 /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/CorePlugin.php(285): Sabre\DAV\Tree->delete(‘myfile.fil…’)\n#2 [internal function]: Sabre\DAV\CorePlugin->httpDelete(Object(Sabre\HTTP\Request), Object(Sabre\HTTP\Response))\n#3 /var/www/nextcloud/3rdparty/sabre/event/lib/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\n#4 /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php(459): Sabre\Event\EventEmitter->emit(‘method:DELETE’, Array)\n#5 /var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php(248): Sabre\DAV\Server->invokeMethod(Object(Sabre\HTTP\Request), Object(Sabre\HTTP\Response))\n#6 /var/www/nextcloud/apps/dav/appinfo/v1/webdav.php(60): Sabre\DAV\Server->exec()\n#7 /var/www/nextcloud/remote.php(165): require_once(’/var/www/nextcl…’)\n#8 {main}",“File”:"/var/www/nextcloud/apps/dav/lib/Connector/Sabre/File.php",“Line”:343,“User”:“”}

Well, I finally found a post that mentioned to run this in the root of nextcloud:
sudo -u www-data php occ files:scan --all

That fixed it.


sudo -u www-data php occ files:scan --all
Not worked for me…
Still i cannot delete folder…
I get this message:
Exception while scanning: File entry could not be inserted with insertIfNotExist() but could also not be selected with getId() in order to perform an update. Please try again.

Help ?

Ok, then it most probably is a file System error.

You should let your filesystem be checked with scandisk (Windows Filesystems) or e2fsck (Linux Filesystems). Search the Internet for detailed tutorials.


Tried all of the above and cant get a Folder deleted. Deadlock found error

Is a sudo -u www-data php occ files:scan – do also check for file if i’m using Object Storage as primary way to keep files?

I tried the above steps, didn’t work for me.

Also the table got some entries with lock state -1 or 2. What do those mean? Do I have to delete them aswell?

For those that do not know how to connect or even the owncloud database name in mysql (mariadb) , follow these instructions :

0 - put your nextcloud under maintenance mode on config.php , so no one access it while you are doing changes .

1st - open your config.php in your nextcloud server folder under “config” folder .

2nd - there should be a field the like this : " ‘dbname’ => " , in this field there is your database name .

3rd - open a terminal window and execute under a root account :

  • mysql -u root -p
    "enter your password"

then connect to nextcloud database with the following command :

  • connect database
    database = your config.php databasename field

after this point all you have to do is to issue the sql command to delete all data inside the oc_file_locks table

-DELETE FROM oc_file_locks WHERE 1;

then after this point all you have to do is :

to close sql prompt and you are done .

Remove the maintenance mode from config.php and start uploading your files over web interface or dav .


I have similar troubles with a Nextcloud installation that I migrated from an Owncloud installation that I’m running on a Synology diskstation.

This is the database command that I tried:
DELETE FROM owncloud.file_locks WHERE file_locks.lock=1;
but this did not work, so later on I tried:
sudo -u http php56 occ files:scan --all
(note that I had to use the ‘http’ for username instead of ‘www-data’ and that I had to explicitely state the version in the php56 command.)

The scan resulted also in exceptions while scanning:
Exception while scanning: "files/0e3e13890e7b79a0edc572f53b262079" is locked #0 /volume1/web/nextcloud/lib/private/Files/Storage/Common.php(680): OC\Lock\DBLockingProvider->acquireLock('files/0e3e13890...', 1) #1 /volume1/web/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php(588): OC\Files\Storage\Common->acquireLock('files/Familie/B...', 1, Object(OC\Lock\DBLockingProvider)) #2 /volume1/web/nextcloud/lib/private/Files/Storage/Wrapper/Wrapper.php(588): OC\Files\Storage\Wrapper\Wrapper->acquireLock('files/Familie/B...', 1, Object(OC\Lock\DBLockingProvider)) #3 /volume1/web/nextcloud/lib/private/Files/Cache/Scanner.php(148): OC\Files\Storage\Wrapper\Wrapper->acquireLock('files/Familie/B...', 1, Object(OC\Lock\DBLockingProvider)) #4 /volume1/web/nextcloud/lib/private/Files/Cache/Scanner.php(420): OC\Files\Cache\Scanner->scanFile('files/Familie/B...', 3, '157625', NULL, true) #5 /volume1/web/nextcloud/lib/private/Files/Cache/Scanner.php(388): OC\Files\Cache\Scanner->handleChildren('files/Familie', true, 3, '157625', true, 53184942) #6 /volume1/web/nextcloud/lib/private/Files/Cache/Scanner.php(391): OC\Files\Cache\Scanner->scanChildren('files/Familie', true, 3, 157625, true) #7 /volume1/web/nextcloud/lib/private/Files/Cache/Scanner.php(391): OC\Files\Cache\Scanner->scanChildren('files', true, 3, 23, true) #8 /volume1/web/nextcloud/lib/private/Files/Cache/Scanner.php(322): OC\Files\Cache\Scanner->scanChildren('', true, 3, 21, true) #9 /volume1/web/nextcloud/lib/private/Files/Utils/Scanner.php(196): OC\Files\Cache\Scanner->scan('', true, 3) #10 /volume1/web/nextcloud/apps/files/lib/Command/Scan.php(159): OC\Files\Utils\Scanner->scan('/jan') #11 /volume1/web/nextcloud/apps/files/lib/Command/Scan.php(227): OCA\Files\Command\Scan->scanFiles('jan', '/jan', false, Object(Symfony\Component\Console\Output\ConsoleOutput), false) #12 /volume1/web/nextcloud/3rdparty/symfony/console/Command/Command.php(256): OCA\Files\Command\Scan->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #13 /volume1/web/nextcloud/core/Command/Base.php(161): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #14 /volume1/web/nextcloud/3rdparty/symfony/console/Application.php(818): OC\Core\Command\Base->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #15 /volume1/web/nextcloud/3rdparty/symfony/console/Application.php(186): Symfony\Component\Console\Application->doRunCommand(Object(OCA\Files\Command\Scan), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #16 /volume1/web/nextcloud/3rdparty/symfony/console/Application.php(117): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #17 /volume1/web/nextcloud/lib/private/Console/Application.php(169): Symfony\Component\Console\Application->run(NULL, NULL) #18 /volume1/web/nextcloud/console.php(90): OC\Console\Application->run() #19 /volume1/web/nextcloud/occ(11): require_once('/volume1/web/ne...') #20 {main}

My Nextcloud client is still giving errors like:
Error transferring - server replied: Locked

Do you have any suggestions?

I did some further investigations and noted that the owncloud.file_locks table had some more rows where the lock was <> 0, but not 1:
SELECT * FROM owncloud.file_locks WHERE file_locks.lock<>0;
which resulted in:
| id | lock | key | ttl |
+-------+------+----------------------------------------+------------+ | 14 | -1 | files/0e3e13890e7b79a0edc572f53b262079 | 1459283811 | | 15 | -1 | files/4f8cbf29cadcc31429f83d792e806885 | 1459283811 | | 89 | 26 | files/e96e1dcb01f6d44a74247b4ec38f0170 | 1496838714 | | 22846 | 27 | files/46e069d0509232e543a2112007e46765 | 1496838719 | | 22848 | 26 | files/bc4e386d83896b627f63b4e7f48c2d1e | 1496838719 | | 23877 | 25 | files/27de4bb5c6042f2a920e605c9884fdcd | 1496840605 | +-------+------+----------------------------------------+------------+

I deleted the rows where the lock value is -1
DELETE FROM owncloud.file_locks WHERE id=14;
DELETE FROM owncloud.file_locks WHERE id=15;

This solved the problem that I was encountering.

Note that there are also files with a lock value of 25, 26, and 27. I did not research the meaning of these values yet, nor the meaning of -1.


Some remarks to the initial post at the top of this thread:

  1. The SQL statement overthere is not completely correct.
    a. In my Nextcloud the table was just named file_locks
    b. The where clause should be something like: WHERE file_locks.lock=1
  2. The SQL command I used is:
    DELETE FROM owncloud.file_locks WHERE file_locks.lock=1;
  3. There can be other lock values then 0 and 1 as well, like -1, 25, 26, and 27. I had to delete the ones with value -1 as well.

See my above posts for more details.

1 Like
'maintenance' => true,
'filelocking.enabled' => false,

These two items helped me fix the problem.

  1. I put Nextcloud in maintenance mode
  2. Used Adminer to access the file_locs table.
  3. The “lock” field in most rows was zero. In others it was 17, 11, or 4. I changed all these values to zero.
  4. Went to the Web interface, and deleted the stubborn items in question.
  5. Went back to Adminer, and reset the values to what they were previously.
  6. Confirmed operation by creating then deleting the same name files and folders using identical paths.

I am on a shared server, so turned off file locking, and am monitoring the situation.

Thanks for the great info.



I’m running into the locking problem and found this text. It is a very good guidance. It hould be part of the authoritive answer!

But the text of the last 2 bullets of the permanent solution seem to contradict.
Bullet 2 states "You can disable the file locking,"
Bullet 3 states "Disabling is no solution"
Is the last bullet a comment on the 2nd? Or are they talking about 2 different "disablings"
Can someone edit it to solve this once and for all?



I had the problem with locked files too. In my case I found that I have cron job configured to start through AJAX. Problem was, that I rarely used web interface, so after I run cron.php manually in Nextcloud install root, everything went to normal. I also configured it to run as a cron job every 15 minutes. See manual how to configure Nextcloud cron jobs.

what are the reasons of file locked ? Is it normal ?


I had this issue when I tried to delete a file, but it resulted in an Apache segmentation fault. I fixed this bug and tried to delete the file again but this time it was locked.

So I think the issue is that Nextcloud locks the file before trying delete it and then, if there’s a crash or other error, the lock is never released.

I think the UI should make it clearer what file is locked and provide some way to unlock it. Or, better, have some mechanism to prevent files from being locked and never unlocked afterwards.

1 Like

If this is your own server then you should set up Redis like @tflidd recommends.

Before following this suggestions, I would like to know…

For what purpose file locking was created ?

I have 40.000 entries in my oc_file_locs table, that seems a little too much for me!
Also wiping out all of this locks, seems a bit dangerous to me just to fix 1 problem (I can’t delete a folder…)

1 Like

As far as i know its there, so that you no other process can access the file while it is written, or otherwise processed.

The issue is, that there is maybe a logical inconsistency, since i could not find an “1” entries under the lock column. If you delete all entries, they will be rebuild automatically when you exit maintenance mode, but this time in a correct order. I tried this on a testsystem, before applying this on our production mashine, and it worked just fine.

Keep in mind, i drew some assoumtions here. I would be happy if someone could either confirm this, or correct me if nessecary.