File cannot be deleted. Database probably corrupted


I encountered a very strange error I cannot fix. Before proceeding further, I must say that I do not think someone would be able to to re-make this error and see for yourself.

I think my problem lies somewhere within a database my Nextcloud instance is connected to.


Few months ago I created a file “New Recording 3.m4a” which was uploaded from my smartphone via the official Nextcloud application for Android devices. The file was there since then and I didn’t have any problems with that. The problem started when I downloaded the official Nextcloud syncing application meant looking for changes made to the files I wanted to upload automatically.

I tested it on GNU/Linux and it showed me that the files cannot be downloaded (I mean the files other than the one I stated above). It’s strange, because I opted out the folders different than the “probably” corrupted file was. Nada, it told me that files cannot be downloaded. Even the ones which where in a different locations than the file.

I did this on Windows 10 and macOS. The problem persisted and resulted the same on every device. I also tried to do something on Android, and you might already guess - it didn’t work.

If I couldn’t download files, I tried to delete the corrupted file. This is the moment when the things started to go out of control.

First, it showed me that there’s an error deleting this very file. It showed me that this file is shared with someone, but hell no! I don’t remember sharing this file with anyone. I have a very tight security and I made sure no one would ever be able to enter my cloud without permission.

Look at that:

Strange, isn’t it?

If I couldn’t delete the file, I checked if I would be able to extract some information from the file. Nope, I was not able to do anything.

Look here:

It gets even stranger than that.

I quickly looked at logs.

Look with me:

That’s really strange. What does it take to delete a single file?

The database must not be in mood, I think.

…here goes the log for a single entry:

Now, you must think I didn’t search the forum for a problem I stated, right? Nope, I was trying to extract as much information as I could to fix the error and I must say that I give up.

This is not the problem with “file lock” . I’ve already had this problem twice and I know how I can deal with that. I assure you that my problem is not the same as the “file lock” error.

I think that something must have happened when the server had to “hard” restart and Nextcloud was not able to save changes to the database. I think this is the most reasonable explanation to this problem, but that’s not the case. I want this to be fixed no matter what. My instance has been running error free for almost a year and I would like to keep with that.

If there’s anyone who knows how to deal with this. Don’t hesitate, it will also help the others, who might encounter the same error as mine.

If you have any pieces of advice, that’s also really appreciated.

Depending on your setup, you might be able to get things in shape again, by performing the following three steps:

  • stop NC and save your complete DB (make an export, if you can)
  • truncate the oc_filecache and oc_share in the NC database
  • run a occ files:scan --all

That will do two things:

  • scan your data folder and re-populate your oc_filecache, which is used by NC to determine what files belong to what account
  • remove all shares, as they are likely borked anyway

Startup your NC instance and test.


First of all, I must thank you for trying to help me, but I have two questions.

  1. Can you guide me with exporting database, please?
  2. Could you please explain me what do you mean with truncating the oc_filecache and oc_share?

I would be extremely glad if you answered my questions!

Can you tell me more about your setup? I need to know, what enviroment you are using. You’ll need cli/terminal access to your NC instance to perform these actions.