-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
File cache table excessively large (and does not shrink after data removal) / Nextcloud should defragment file cache table #7312
Comments
Yes, there is no way with NC commands to reduce oc_filecache table if files&folders are deleted or renamed outside NC. It seems the same apply to external shares. If changes are made outside, NC can only add files to oc_filecache. I my case oc_filecache was expanded due large amount of photos and previews generated by previewgenerator app (20 previews for each photo generated by default). Every preview is also registered in oc_filecache table. I had to modify previewgenerator, manually delete all previews and all db records for files that referenced to preview folder. Then regenerate reduced amount of previews again. It's time consuming process. There is definitely need for NC maintenance command which keep oc_filecache table optimized according to local filesystem. It would also allows more easily to use NC for fastlane file upload and managing with direct Samba/FTP shares. Because http/webdav upload for numerous files is lagging and not as robust and safe as Samba/FTP. |
cc @icewind1991 |
@ArnisR: That would explain the size of the file cache: The external disk hosted my photo library and was indexed by previewgenerator. So how would I proceed to reduce the file cache manually? Is there a way to simply clear the table and regenerate it? |
@ruedigerkupper : I can't say. There are several other records regarding NC system in that table, not only files. So I wouldn't do it. I saw a thread where someone presented php file which make comparison of actual files and records in database and delete db records for the non-existent. But nobody confirms it's working and my knowledge of MySQL is too short to make conclusion. I didn't risk. Because most overhead was due experiments with previews I'd managed only them. I put NC in maintenance mode and made backup of database. Delete all content of appdata_.../preview/ folder. With phpmyadmin selected (with search) all records in oc_filecache table where column "path" contain appdata_your-NCspecificpath-here/preview/ and deleted them. I have NC12. I don't know maybe NC11 put previews in different folder (under each user). Then I modified previewgenerator - nextcloud/previewgenerator#78 Switch maintenance mode off and run preview:generate-all. In my case it takes almost 3 days to finish generating them for ~85 K photos on i3 CPU. At this moment I have problem with this - #7269 |
Thanks, ArnisR! It have meanwhile solved my problem, and it turned out too be much easier than that:
Note "Data_length" (=21 MB) and "Data_free" (=19 GB)!! So, the removed files had actually been cleaned from the file cache, but the InnoDB table was so badly fragmented that it occupied 1000 times the disk space needed for its data. Going through the mysql reference, I came about https://dev.mysql.com/doc/refman/5.7/en/innodb-file-defragmenting.html. That states that an InnoDB table can be defragmented by issuing a "no-op" ALTER TABLE command:
And -- magically -- this reduced the table to a file size of 8 MB (!!!):
SummarySo let's get this straight:
Feature requestNextcloud should defragment the oc_filecache table regularly, probably as part of the regular maintenance cron job. |
Same issue here, our internal next cloud service has only a few hundred users, but the database was over 130GB. We just upgraded from owncloud 9 to nextcloud 12.0.4 and manually cleared the oc_filecache table leaving only the shared links ( with the php script ArnisR mentioned), this leaves only about 400MB, with the scan for all local directories, the database size is only at 700MB(only 2TB data locally), and the web interface functions normally (the service will rescan mounted directories when a user enters that mounted directory, and display the files). With a closer look at the file system, we found out of the space database inserts are from different users mounting the same file systems over smb (the fs has a few PB of data). The bit of annoying thing is when doing the occ files:scan $user command, the service will actually try to scan all the mounted folders this user have, including the smb mounted folder, which takes forever, we couldn't afford to have users waiting for those scans, so wrote a script to scan only local files. So here are a few suggestions:
|
Maybe an explicit occ command is fine. But I'm really against doing this in a regular cron job as it rebuilds the table basically. So on larger instances that is not a good idea. |
Same issue here with a 80GB oc_filecache.ibd while my entire database is roughly 4TB. @ArnisR , @LnLogN, could you give a link to the php script you are mentioning? @ArnisR, could you give an idea on how long the defragmenting took for you? For Info, I could get the oc_filecache.ibd growing rate from recent backups: |
same issue here. my database was 61gigs with only 400gb of data. I had the root of an external ubuntu server mounted... ~73,918,234 ROWs! lol. anyways is there a way to prevent the indexing of external shares? |
Same issue here 20Go of DB for 200Go of local data |
This comment was marked as duplicate.
This comment was marked as duplicate.
MySQL regulary stops working because of this:
|
*bump I'm quite surprised that there is no "clean up files in index that have actually been deleted on disk" functionality in Nextcloud, since this is obviously vital to keep Nextcloud running smoothly. I wonder, we also have SMB mounted external storages and for those Nextcloud automatically cleans up the filecache for files that get deleted (and I did not activate the notify feature as far as I'm aware) ... why does this not work for local files? |
Is this fixed? I have local storage mapped using the local filesystem, and I not only don't delete files from inside nextcloud, but I delete them from a windows machine over samba to the filesystem directly. A folder that gets hundreds of files added and deleted daily only has 226 entries, like I'd expect, so that's nice to see. I run this, which I don't think has any cleanup scripts https://github.com/crazy-max/docker-nextcloud EDIT: Okay, it just cleans them up when I enter each folder, but if I don't, then it gets bigger. |
I am now having the same ish issue. 18G /var/lib/mysql/next/oc_filecache.ibd 18G for 5x users (testing) and keeps increasing rapidly is a bit much. We are only using nextcloud with external smb shares, nothing local. This 18G has been gathered in 3 months. Also, I have 34 million rows, so de-fragment in my case I doubt will do anything, not much free data: mysql> show table status like "oc_filecache" \G; |
My instance with SMB connection only runs flawless without Cron, but with Ajax. No db table blows up. |
I just came across this thread after having my database lock up and kill my server because it kept getting thrown into recovery mode.
|
THe same problem with NC 18.0.3... after years no solution? show table status like "oc_filecache" \G; I was voting for NC on every occasion, but things like this are just ridiculous... |
The same problem on nextcloud 17.0.2 |
BUMP: |
Got this problem too. Increased the VM disk size already a month ago. It doubled in a month from 8 GB to 16 GB without adding any files. No external drive removed. Just a nextcloud instance sitting there. Was on 21.0.4 or so, just upgraded to 21.0.5 and now upgrading to 22.2.0 Basically this problem arose this summer with more or less the same files which were on this server all the time. Edit:
It seems that mysql's binlog keeps growing on my machine:
I continue to investigate this and leave this note here since this can be a culprit as well. Edit 2:
I lowered the binlog expiration time from 30 days to one week:
Restart the mysql service and voilà:
This lowered the footprint drastically:
|
Same problem: Now I set 'binlog_expire_logs_seconds = 172800' If I check these files using 'less' I see mostly ics calendar data. 🧐 |
ok, now my honest opinion, checking this issues here and other issues of that product and having a look at filecache structure. well that table looks like the most important table of nextcloud taking the most work on larger filecollections. Despite it is so important, the structure is not efficient, badly normalized and the handling in nexctloud lacks of features, which leads to performance-, ressource- and stability- problems (like deadlocking, swapping files out, timeouts) as such. I even wonder how larger workload can be handeld by this. For example: my table has about 1.299.481 entries (which i consider to be a small system). The Datasize itself is ~355 MB (Mariadb, Dynamic Rows). Yesterday the Index size was about 655 MB. So the indices are larger, than the table itself (the Database is defragmented and optimzed). This as such is an inidcation of bad tablemanagement. Having a look at the used querys and needed memory/buffers/tempfiles on database also indicates this. So what i am suggesting: Do the maintainers see a chance to refactor the table management of the filecache in NC completly? Until now, my time has been very short, but i may help with that having experience in other systems with refactoring databasestructures and code. I am sure, doing this would be a big benefit for Nexcloud to get accepted in more companies... I just don't want to start something and get some "we won't do this". And maybe it will take time and help, but i would like to think about getting into this. I would be happy to hear some opinions from the maintainers here. |
This comment was marked as duplicate.
This comment was marked as duplicate.
Please consider opening a new issue for the binlog problem. This issue is about oc_filecache and your problem seems to be unrelated to that (correct me if that's wrong). |
Thanks @ruedigerkupper, you are right - I just replied to @cls-nebadje 's comment about the same topic. |
same issue here - also have excessive writes which already killed a SSD: #22419 |
@flotpg This deletes all favourites of the users. |
Please see above: |
Thanks @ruedigerkupper |
OPTIMIZE TABLE or mysqloptimize should also do the trick. |
No, they won't - also truncation oc_filecache is not a solution, as the table will be populated again when accessing the files or do a scan. imo still, the big writes and reads are also realated to bad structure of the table, building up large index-tables. what helped for me was to remove those indexes: After that, do optimize table. NC will than complain about those indices missing, but i checked and i am fine with them missing. That cut my tablesize into half without deleting data, reducing writes and reads massively all the time in cost of a few (very few) slower reads in special cases. Maybe you want to try this and report. |
When i extract the 10 bigger tables of my instances I have :
When I activate slow query log I have many queries on The most important query (they take many time and called many times) is
In your opinion, is it possible to move part of |
No, as long as the structure is that bad, it would not improve the situation to put the data from one database to another. Maybe you want to reduce the size by deleting the incidces i mentioned above and have a look what happens. |
The name column is not search for '?' it's a generalization of many queries for different names. In your opinion, what is the target new design ? |
the table should be normalized - read about the basics of normalisaition of a table. it should be splitted and character-fields should only be used as values to search for. the path should be split in another table and so on... just normalization as a clean design would be. cant explain in details, relies on the usage a bit. but the way its done now its not working good in any way. |
Normalization always makes performance slower. It never makes anything faster. That's because with normalization, you'll need to use JOINs, meaning - extra tables, extra look ups, extra indexes |
I'm not comfortable with the code but I feel that the code that uses this table could be split into subdomains. A DDD approach seems to me to be more effective in the long run. In a short term I feel replacing frequent queries by "cache" could be a good idea. |
this in fact is wrong. normalization is the reason for relational databases as we use today. but of course it is important to understand the benefits and to use it wisely. regarding filestructure a normalization would be a good approach. look at the tablesizes and indexsizes that are used now. they are clearly not good, causing the database to do a lot stuff it shouldnt do. Like always swapping to disk and going down to full table scans. I had some of bad designed tables in my life and fixed it by better design, this one here is clearly needing a change. It just, that i am not used to mysql and nextcloud sadly...
This is what indices are for and would be a general solution for this problem, but you cant do in the current structure. Indices are caches for a part of the table designed for faster reading speed by keeping only relevant, smaller parts in memory as possible. It will work if they are used tight to the needs, but right now there are duplicated and as large as the data itself. This is why currently they are slowing everything down and causing high disk usage. This is why you are faster deleting them as i stated before (read my suggestion above to delete those indices). This is why i honestly look for changes here as there are: Do normalization, clean up indices and go through the basic queries to improve nextcloud performance and reduce space waste. |
just to leave a reference here: Looks like its related to the same behaviour as #6899. See my proposal to reduce deadlocks by changing indices on table oc_filecache. Can you check #6899 (comment) and leave a thumb up there if it works? Would not really do defrag, but would prevent the indexsize to get that large, as it is using default indices, so Table would not grow that large. |
Perhaps a check with a warning could be added for the fragmentation scenario (https://dev.mysql.com/doc/refman/8.0/en/innodb-file-defragmenting.html) somewhat like exists for missing indexes? |
If you are using external storages please make sure to configure an authentication mechanism that matches your usecase:
If two users connect to the same service using different credentials Nextcloud will assume they are seeing different storages. This will of course blow up your filecache. it will also prevent collaboration on files. There's no way for Nextcloud to tell that two users are seeing the same data. |
It's been a long time since I've used it, so this may not be relevant anymore. I only had a single user and still had this issue. |
Good evening, I'm having the exact same issue but in my case it resulted with my snap instance breaking in a very weird way. |
Problem
My nextcloud instance (small-scale, single-server setup, 6 users) has an excessively large database size (20 GB as of today). This size doesn't sensibly relate to the amount of data managed (approx. 1 TB, now reduced to 4.3 GB).
I have found that almost all of the 20GB is located in a single table, the file cache:
This file seems to grow and grow, but never shrinks.
Further details
Here’s something I don’t understand: there should be thousands of orphaned entries now that most of the data is gone!
=> I suspect that my file cache table is somehow broken, but I don’t know how to fix it. I believe I should clear the table and reproduce it, but I do not know how to do that.
Steps to reproduce
Unsure, sorry
Expected behaviour
Flie cache table should shrink after external storage was removed.
Actual behaviour
File cache table stays the same (and is excessively large)
General server configuration
Operating system: Linux helge 4.13.0-17-generic #20-Ubuntu SMP Mon Nov 6 10:04:08 UTC 2017 x86_64
Web server: Apache/2.4.28 (Unix) OpenSSL/1.0.2g (fpm-fcgi)
Database: mysql 5.7.18
PHP version: 7.0.23
PHP-modules loaded
Nextcloud configuration
Nextcloud version: 11.0.5 (stable) - 11.0.5.1 (snap version 3680)
Updated from an older Nextcloud/ownCloud or fresh install: Nextcloud snap, updated from previous snap versions (3317, 2707)
Where did you install Nextcloud from: snap
Are you using external storage, if yes which one: \OC\Files\Storage\Local, see description for details!
Are you using encryption: no
Are you using an external user-backend, if yes which one: Nextcloud sync client from the ubuntu store
Enabled apps
Disabled apps
Content of config/config.php
Client configuration
Browser: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1 (KHTML, like Gecko) Version/11.0 Safari/605.1 Ubuntu/17.10 (3.26.1-1ubuntu1) Epiphany/3.26.1 (Web App)
Operating system: GNU/Linux (Ubuntu 17.10)
The text was updated successfully, but these errors were encountered: