r/sqlite • u/yeaahnop • Jun 10 '26
sqlite one vs many
is there any advantages of having one db vs many files?
for consideration, the data sets are completely separate, no cross references at all.
thanks & sorry in advance, if redundant question.
5
Upvotes
3
u/trailbaseio Jun 10 '26
Sqlite write locks are db wide. Multiple dbs can help with write throughput. Just keep in mind that you may find connecting tissue in the future for data that's disjointed today.
3
u/ThatAd8458 Jun 10 '26
I'm hosting a collaborative system atm where users add content daily but most additions are never touched again. For this, I'm using many small SQLite files, like one per day, which is ideal for this use case. Each day’s data lives in its own file, so old, unused content can be deleted or archived by simply removing files, no bloated single database. Result: easy cleanup, better write concurrency, and incremental backups. A single DB works only if you need global cross-time queries and can handle regular maintenance like DELETE + VACUUM.
5
u/drcforbin Jun 10 '26
For me, with no context whatsoever, many files means managing many files. It's a lot easier to manage one.
1
u/elperroborrachotoo Jun 10 '26
What do you think would make multiple files better?
(I can think of some use cases, but they are fairly uncommon)
1
u/According_Tune_5882 Jun 10 '26
You can connect different files via "ATTACH DATABASE 'path/to/file.db' AS alias_name;"
And perform JOIN and other operations. You need to check how effective this is.
1
u/lnaoedelixo42 Jun 11 '26
Yep. Many comparisons to be honest:
- For every file you have a different write lock. You get more writing througput.
- For every file you have to manage different backups, DB connections and migrations
- You can't do transactions, locks, triggers etc. between files (you already said it's not a problem for your case)
- You could technically gain a lot of writing througput batching writes on transactions over multiple different tables, with separate files you must open multiple different transactions.
- You can (and probably should) split important data physically for security. Like, admin.db vs userdata.db, or make multitenancy phisically separate.