Skip to content

SQLite database doesn't scale well to very large setups #10264

Open

Description

@gabest11

What happened?

Extreme slowdown around files=60000

Syncthing version

v2.0.1

Platform & operating system

Ubuntu x86_64

Browser version

Chrome

Relevant log output

drwxr-xr-x 2 root root          7 Aug 15 05:48 .
drwxr-xr-x 4 root root         11 Aug 14 19:47 ..
-rw-r--r-- 1 root root 1464545280 Aug 14 20:48 folder.0001-cxtfdwnt.db
-rw-r--r-- 1 root root 2499584000 Aug 14 22:46 folder.0002-6yenjrsk.db
-rw-r--r-- 1 root root 5970890752 Aug 15 05:48 folder.0003-aqebwydr.db
-rw-r--r-- 1 root root 6874693632 Aug 16 13:57 folder.0004-ce9z7tuv.db
-rw-r--r-- 1 root root      32768 Aug 15 05:48 main.db

2025-08-15 05:48:08 INF Migrated folder (folder=ho9ih-upint files=78200 blocks=26759019 duration=7h1m41s filesrate=3.0907341846073693 log.pkg=syncthing)
2025-08-15 05:48:37 INF Still migrating folder (folder=j4z5v-vz39u files=1000 blocks=798267 duration=28s filesrate=34.82737300988369 log.pkg=syncthing)
2025-08-15 05:49:13 INF Still migrating folder (folder=j4z5v-vz39u files=3000 blocks=1644245 duration=1m4s filesrate=46.42943790701229 log.pkg=syncthing)
2025-08-15 05:50:12 INF Still migrating folder (folder=j4z5v-vz39u files=4000 blocks=2971821 duration=2m4s filesrate=32.222944340338266 log.pkg=syncthing)
2025-08-15 05:51:27 INF Still migrating folder (folder=j4z5v-vz39u files=5000 blocks=3929694 duration=3m18s filesrate=25.155727297841644 log.pkg=syncthing)
2025-08-15 05:51:40 INF Still migrating folder (folder=j4z5v-vz39u files=7000 blocks=3951881 duration=3m32s filesrate=33.00036047152695 log.pkg=syncthing)
2025-08-15 05:51:54 INF Still migrating folder (folder=j4z5v-vz39u files=9000 blocks=3975106 duration=3m45s filesrate=39.912434834856114 log.pkg=syncthing)
2025-08-15 05:52:05 INF Still migrating folder (folder=j4z5v-vz39u files=11000 blocks=3999106 duration=3m57s filesrate=46.350966632697286 log.pkg=syncthing)
2025-08-15 05:52:23 INF Still migrating folder (folder=j4z5v-vz39u files=14000 blocks=4032413 duration=4m15s filesrate=54.87924133322014 log.pkg=syncthing)
2025-08-15 05:52:35 INF Still migrating folder (folder=j4z5v-vz39u files=16000 blocks=4056182 duration=4m26s filesrate=60.04079957985109 log.pkg=syncthing)
2025-08-15 05:52:48 INF Still migrating folder (folder=j4z5v-vz39u files=18000 blocks=4076647 duration=4m40s filesrate=64.24128426074937 log.pkg=syncthing)
2025-08-15 05:53:00 INF Still migrating folder (folder=j4z5v-vz39u files=20000 blocks=4100987 duration=4m52s filesrate=68.41771303360628 log.pkg=syncthing)
2025-08-15 05:53:12 INF Still migrating folder (folder=j4z5v-vz39u files=22000 blocks=4121670 duration=5m4s filesrate=72.283037756679 log.pkg=syncthing)
2025-08-15 05:53:26 INF Still migrating folder (folder=j4z5v-vz39u files=24000 blocks=4148840 duration=5m18s filesrate=75.37777479461357 log.pkg=syncthing)
2025-08-15 05:53:37 INF Still migrating folder (folder=j4z5v-vz39u files=26000 blocks=4171157 duration=5m28s filesrate=79.08382031892452 log.pkg=syncthing)
2025-08-15 05:53:49 INF Still migrating folder (folder=j4z5v-vz39u files=28000 blocks=4192877 duration=5m40s filesrate=82.24159672945815 log.pkg=syncthing)
2025-08-15 05:54:02 INF Still migrating folder (folder=j4z5v-vz39u files=30000 blocks=4216711 duration=5m53s filesrate=84.78229497742171 log.pkg=syncthing)
2025-08-15 05:54:13 INF Still migrating folder (folder=j4z5v-vz39u files=32000 blocks=4240299 duration=6m4s filesrate=87.67989653257354 log.pkg=syncthing)
2025-08-15 05:54:25 INF Still migrating folder (folder=j4z5v-vz39u files=34000 blocks=4261532 duration=6m16s filesrate=90.30028321260272 log.pkg=syncthing)
2025-08-15 05:54:39 INF Still migrating folder (folder=j4z5v-vz39u files=36000 blocks=4284417 duration=6m30s filesrate=92.17907230396419 log.pkg=syncthing)
2025-08-15 05:54:49 INF Still migrating folder (folder=j4z5v-vz39u files=38000 blocks=4305329 duration=6m40s filesrate=94.79852282290771 log.pkg=syncthing)
2025-08-15 05:55:53 INF Still migrating folder (folder=j4z5v-vz39u files=40000 blocks=4623722 duration=7m44s filesrate=86.02965201399978 log.pkg=syncthing)
2025-08-15 06:03:13 INF Still migrating folder (folder=j4z5v-vz39u files=41000 blocks=5835964 duration=15m5s filesrate=45.294194127375256 log.pkg=syncthing)
2025-08-15 06:07:23 INF Still migrating folder (folder=j4z5v-vz39u files=42000 blocks=6895282 duration=19m14s filesrate=36.37407214514885 log.pkg=syncthing)
2025-08-15 06:13:17 INF Still migrating folder (folder=j4z5v-vz39u files=43000 blocks=7961010 duration=25m9s filesrate=28.49014959396606 log.pkg=syncthing)
2025-08-15 06:22:18 INF Still migrating folder (folder=j4z5v-vz39u files=44000 blocks=9200041 duration=34m10s filesrate=21.461389060236137 log.pkg=syncthing)
2025-08-15 06:34:42 INF Still migrating folder (folder=j4z5v-vz39u files=45000 blocks=10449366 duration=46m33s filesrate=16.109113848502837 log.pkg=syncthing)
2025-08-15 06:48:50 INF Still migrating folder (folder=j4z5v-vz39u files=46000 blocks=11779108 duration=1h0m42s filesrate=12.629995141571909 log.pkg=syncthing)
2025-08-15 07:05:07 INF Still migrating folder (folder=j4z5v-vz39u files=47000 blocks=13123479 duration=1h16m58s filesrate=10.176192222482983 log.pkg=syncthing)
2025-08-15 07:24:59 INF Still migrating folder (folder=j4z5v-vz39u files=48000 blocks=14445136 duration=1h36m50s filesrate=8.260527181141303 log.pkg=syncthing)
2025-08-15 07:45:10 INF Still migrating folder (folder=j4z5v-vz39u files=49000 blocks=15789964 duration=1h57m2s filesrate=6.977861741577258 log.pkg=syncthing)
2025-08-15 08:06:44 INF Still migrating folder (folder=j4z5v-vz39u files=50000 blocks=17098053 duration=2h18m36s filesrate=6.012371397283919 log.pkg=syncthing)
2025-08-15 08:29:15 INF Still migrating folder (folder=j4z5v-vz39u files=51000 blocks=18287685 duration=2h41m7s filesrate=5.275604933032928 log.pkg=syncthing)
2025-08-15 08:55:48 INF Still migrating folder (folder=j4z5v-vz39u files=52000 blocks=19716660 duration=3h7m40s filesrate=4.6180071152808795 log.pkg=syncthing)
2025-08-15 09:12:29 INF Still migrating folder (folder=j4z5v-vz39u files=53000 blocks=20860162 duration=3h24m20s filesrate=4.322798436811022 log.pkg=syncthing)
2025-08-15 14:22:09 INF Still migrating folder (folder=j4z5v-vz39u files=54000 blocks=22008056 duration=8h34m1s filesrate=1.7509003440962674 log.pkg=syncthing)
2025-08-15 14:41:33 INF Still migrating folder (folder=j4z5v-vz39u files=55000 blocks=23171606 duration=8h53m24s filesrate=1.7185121172689344 log.pkg=syncthing)
2025-08-15 15:05:21 INF Still migrating folder (folder=j4z5v-vz39u files=56000 blocks=24352515 duration=9h17m13s filesrate=1.6749739417664866 log.pkg=syncthing)
2025-08-15 15:31:45 INF Still migrating folder (folder=j4z5v-vz39u files=57000 blocks=25543778 duration=9h43m36s filesrate=1.627790431446665 log.pkg=syncthing)
2025-08-15 16:05:49 INF Still migrating folder (folder=j4z5v-vz39u files=58000 blocks=26913078 duration=10h17m40s filesrate=1.5649987765502067 log.pkg=syncthing)
2025-08-15 16:23:51 INF Still migrating folder (folder=j4z5v-vz39u files=59000 blocks=27653436 duration=10h35m42s filesrate=1.5468107882790405 log.pkg=syncthing)
2025-08-15 16:55:38 INF Still migrating folder (folder=j4z5v-vz39u files=60000 blocks=28801680 duration=11h7m29s filesrate=1.4981475792678973 log.pkg=syncthing)
2025-08-16 05:12:21 INF Still migrating folder (folder=j4z5v-vz39u files=61000 blocks=30028318 duration=23h24m12s filesrate=0.7240119024475011 log.pkg=syncthing)

Activity

  1. added theissue type on Aug 16, 2025
  2. added
    bug
    needs-triage
    on Aug 16, 2025
  3. tomasz1986 commented on Aug 16, 2025

    @tomasz1986
    Member

    I assume that "28TB" is the size of your whole data set, right? What is the size of the old database (i.e. the index-v0.14.0.db directory)?

  4. gabest11 commented on Aug 16, 2025

    @gabest11
    Author

    28TB is the current (4th) folder under migration. Third folder was 13TB. First line in the log show that it finished in about 7 hours. That had more files, but less data.

    Whole old db is 9.2GB.

  5. changed the title [-]Large >28TB database migration will not finish before The Heat Death of The Universe[/-] [+]Database migration from v1 to v2 takes very long time in large setups[/+] on Aug 16, 2025
  6. aminvakil commented on Aug 17, 2025

    @aminvakil
    Contributor

    I had the same problem as pointed out in forum, two nodes syncing using syncthing:
    62,122 files 24,678 directories ~13.8 TiB
    One of nodes migrated to v2 in less than an hour.
    The other one seems to freeze after a couple of hours.

    Two nodes are identical in cpu, memory, disks, operating system and everything.

    It got a little faster with ignorePerms true. And right now 60000 file scanning is in 70% after 24 hours.

  7. gabest11 commented on Aug 18, 2025

    @gabest11
    Author

    It took four days, but it has done it. In the end all folders just displayed the Unknown state. I could not do anything. Settings, logs, nothing worked in the GUI. Maybe my config.xml was not fully compatible with 2.x. Deleted everything and now it does the indexing again.

  8. changed the title [-]Database migration from v1 to v2 takes very long time in large setups[/-] [+]SQLite database doesn't scale well to very large setups[/+] on Aug 29, 2025
  9. calmh commented on Aug 29, 2025

    @calmh
    Member

    I think this less about the number of files (although you could run into that as well) and more about the number of blocks, as that tends to be one or two magnitudes higher.

  10. bt90 commented on Aug 29, 2025

    @bt90
    Contributor

    Maybe we can apply some sharding here? The same technique helped us scaling at the folder level. But I fear it's going to be a lot harder as we ultimately need transactional behaviour which won't work across multiple sqlite databases...

  11. calmh commented on Aug 29, 2025

    @calmh
    Member

    Yeah that's what I'm thinking, it's a bit tricky as there are keys towards blocklists and stuff as well, and also we'd need to do this a bit dynamically as it will be a lot of overhead to do sharding for small folders.

    Also trying to come up with potential tradeoffs where we don't store all the block hashes but some sort of partial hint, so that we can shift some work towards when we need to do the block lookup, but nothing obvious comes to mind so far (that would significantly reduce the number of rows to something below the number of blocks in total).

    (The use for this data is when syncing a change, we want to see if we already have a given block locally somewhere in order to avoid downloading it again, and that lookup is by block hash.)

    (https://github.com/syncthing/syncthing/blob/main/internal/db/sqlite/sql/schema/folder/50-blocks.sql for the record)

  12. bt90 commented on Aug 29, 2025

    @bt90
    Contributor

    The blocklists table is the main offender judging from real world stats:

    https://forum.syncthing.net/t/database-or-disk-is-full-might-be-syncthing-might-be-qnap/24930/7

    That's ~85% of the whole DB layer

  13. calmh commented on Aug 29, 2025

    @calmh
    Member

    In terms of size on disk, yes, but the blocks table is going to have orders of magnitude more rows (and hence inserts-per-file). I guess a benchmark is required to determine which is which in terms of taking a long time to insert.

  14. 27 remaining items

  15. eblau commented on Nov 12, 2025

    @eblau

    Thanks @101100! This really helped me out. I run SyncThing on my TrueNAS SCALE server that is based on ZFS. Ever since upgrading to 2.0, I have noticed the syncthing process eating up 200% CPU whenever it is actively syncing some files and the transfers proceed very slowly (1 to 1.5 MBps) whereas before upgrading to 2.0, I could easily get 25+ MBps.

    I set zfs set sync=disabled <dataset> on the SyncThing config ZFS dataset temporarily until the ZFS fix is available and restarted syncthing. Now all the problem symptoms have gone away. CPU usage is low again and transfer speeds are fast. Once ZFS 2.4.0 is available with the fix, I'll re-enable sync on the dataset.

  16. calmh commented on Nov 12, 2025

    @calmh
    Member

    Related, #10454

  17. callegar commented on Feb 11, 2026

    @callegar

    Unclear to me if the issue that I am facing is this one or not. However, after the upgrade to syncthing 2 I am facing issues with high cpu usage, excessive I/O and extremely slow behavior.

    I am using syncthing to sync some source trees (many small files, with some occasionally large build artifacts). Everything was more ore less OK with syncthing 1.3. Now, when updating a large tree I experience hours for sync. This is not spent in file transfers or network slowliness. If I manually sync the files with unison, that takes a few minutes and interstingly even with two trees that are actually already in sync, syncthing spends > 10hours to get to a synced state.

    Everything is on btrfs.

  18. gaby commented on Apr 14, 2026

    @gaby

    We are running into this issue too. We are using Synology FS series with 128GB ram each. We have one syncthing docker container per NAS with +10 folders. Some of them have terabytes of data or millions of files. The volumes are using brtfs, not zfs.

    Everything would be running fine, then randomly syncthing goes into "Unknown" for all folders and becomes unresponsive. At that point CPU usage increases to +1000% and RAM to 20-30GB.

    Stopping and starting the container again fixes the issue for a few hours, then it happens again.

    TLDR: We migrated from Synology Drive to Syncthing for multi-site sync. Main reason being that Synology Drive is not linux friendly and causes thousands of conflicts related to case sensitivity.

    Initial setup for syncthing was great, but once we added big shares, we are constantly running into:

    • Excessive usage of resources.
    • Slow scanning.
    • "Unknown" status for folders.
    • Folders that never stop syncthing.
    • Warning/Errors about UTF-8 normalization.
    • Network I/O usage is very low.
    • We applied all the suggestions from the performance guide.
  19. gaby commented on Apr 22, 2026

    @gaby

    We tried using multiple syncing instances, one per large shared folder, and the issue still persists.

    Syncthing takes several hours to scan a share with 4-5 million files/5 TB.

    CPU usage stays above 1000%, and RAM usage keeps increasing to 30-40GB

  20. gaby commented on Apr 24, 2026

    @gaby

    @callegar Did you find a fix? I'm also using btrfs on a Synology FS (rack mounted models).

    Syncthing has been running for +1 week and it still doesn't finish "Scanning" or doing a "Sync". It is endlessly using tons of CPU/RAM with barely any bytes being sent/received.

    We applied all the options from the performance guide. We also deployed separate Syncthing instances per folder, made 0 difference.

    Any ideas ? @calmh

    The config volume for Syncthing is running on a RAID disks, I don't know if that could be the reason. They are all flash drives though.

  21. callegar commented on Apr 25, 2026

    @callegar
  22. gaby commented on Apr 25, 2026

    @gaby

    @callegar That's been our experience too. We are also trying to use syncthing to sync home dirs.

    Works fine for simple shares.

  23. gaby commented on Apr 26, 2026

    @gaby

    @calmh @callegar I described what I am seeing to Codex and Claude and both concluded that the problem could be related to walker.scan in walk.go running serialized.

    Something like users home-dirs are going to have potentially hundreds of changes every few seconds. For example If I'm using a browser and vscode, both of those applications write files to ~/.cache and ~/.config.

  24. gaby commented on Apr 27, 2026

    @gaby

    @calmh I have a draft for parallel walkers here gaby#8

  25. callegar commented on Apr 27, 2026

    @callegar

    That looks nice. I wonder if it is going to be enough or if there is something inherent in doing too many disk accesses while updating the db. The fact that having the db on ssd or having a system with only rotating media makes so much difference appears significant. Yet, syncthing is often deployed on little NAS-like systems with a large rotating disk and only a tiny solid state memory with the OS. In some cases one only has rotating disk + sdcard.

  26. gaby commented on Apr 27, 2026

    @gaby

    @callegar You are right, the problem could be the database itself.

    That was a reason I tried deploying multiple Syncthing instances, one per shared folder. It made no difference.

  27. aminvakil commented on May 8, 2026

    @aminvakil
    Contributor
  28. kocmo commented on Jun 30, 2026

    @kocmo

    Thanks @101100! This really helped me out. I run SyncThing on my TrueNAS SCALE server that is based on ZFS. Ever since upgrading to 2.0, I have noticed the syncthing process eating up 200% CPU whenever it is actively syncing some files and the transfers proceed very slowly (1 to 1.5 MBps) whereas before upgrading to 2.0, I could easily get 25+ MBps.

    I set zfs set sync=disabled <dataset> on the SyncThing config ZFS dataset temporarily until the ZFS fix is available and restarted syncthing. Now all the problem symptoms have gone away. CPU usage is low again and transfer speeds are fast. Once ZFS 2.4.0 is available with the fix, I'll re-enable sync on the dataset.

    @eblau - I considered doing that, putting Syncthing db on a separate ZFS dataset and disabling sync on it, but this Ycombinator comment got me concerned, quoting:

    "Disabling sync corrupts SQLite databases on powerloss, I've personally experienced this following disabling sync because it causes SQLite to hang.
    You cannot have SQLite keep your data and run well on ZFS unless you make a zvol and format it as btrfs or ext4 so they solve the problem for you.
    "

  29. Nnnes commented on Jul 17, 2026

    @Nnnes

    "Disabling sync corrupts SQLite databases on powerloss, I've personally experienced this following disabling sync because it causes SQLite to hang. You cannot have SQLite keep your data and run well on ZFS unless you make a zvol and format it as btrfs or ext4 so they solve the problem for you."

    @kocmo As mentioned in previous comments here, that comment (written 2025-07-25) is now outdated. ZFS 2.4.0+ (released 2025-12-18) works well with SQLite without requiring sync=disabled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-triage

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions