[SOLVED] Database performance on large (50k notes, 12GByte) database #9138
oschettler
started this conversation in
Show and tell
Replies: 2 comments 2 replies
-
|
@eliandoran Is it feasible? Can it be used directly? It looks very impressive. |
Beta Was this translation helpful? Give feedback.
2 replies
-
|
This is a genuine good use case of LLMs, because the change is relatively small and it can bring a pretty good performance improvement. Personally I haven't noticed these performance issues, but I am glad you found a solution. If we merge #9141 you might want to be careful when upgrading since you've altered the database externally, which Trilium probably won't expect. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I like Trilium very much.
However, with the size of my database, it has recently become barely usable: Unresponsive UI on both the server web as well as in apps synced and connected to it.
For context: I run the server on a Linux machine with 32GByte, 8 cores, big SSD, so, hopfully beefy enough. Both the server and clients are version 0.102.1.
I had Claude take a look at my backend log and it came up with some additional indices on the SQlite database:
I have applied these, after backing up my databases, both on the client machine and on the server. No changes to the application code were required. This has significantly improved the performance in both cases.
Here is the full analysis:
Trilium Notes Database Optimization
Problem
Analysis of
log.txt(19MB, ~75,000 slow query entries) reveals severe performanceissues during Trilium's sync consistency checks. These checks run every ~10 seconds
and execute ~15 queries each, joining the
entity_changestable (1,010,077 rows)against various entity tables.
Worst Offenders
entity_changes JOIN attributes(isErased=1)entity_changes LEFT JOIN attributes(isErased=0)entity_changes LEFT JOIN revisionsattributes LEFT JOIN entity_changesRoot Cause Analysis
The
entity_changestable has only two indices:IDX_entityChanges_entityName_entityId— UNIQUE on(entityName, entityId)IDX_entity_changes_changeId— on(changeId)The sync consistency queries filter by
(entityName, isErased)then join onentityId,but no index covers this combination. The existing UNIQUE index starts with
entityNamebut doesn't include
isErased, forcing SQLite to scan all rows for a givenentityNameand then filter by
isErasedin a second pass.With 640K+ attribute-related rows in
entity_changes, this means scanning hundreds ofthousands of rows every 10 seconds.
Solution: 7 New Indices
Critical (sync performance)
IDX_entity_changes_entityName_isErased_entityIdonentity_changes(entityName, isErased, entityId)IDX_entity_changes_entityName_isErased_entityId_idonentity_changes(entityName, isErased, entityId, id)idandentityIdnever need to access the main table at allImportant (cleanup queries)
IDX_notes_isDeleted_utcDateModifiedonnotes(isDeleted, utcDateModified)IDX_attributes_isDeleted_utcDateModifiedonattributes(isDeleted, utcDateModified)IDX_attachments_isDeleted_utcDateModifiedonattachments(isDeleted, utcDateModified)Minor (general filtering)
IDX_branches_isDeletedonbranches(isDeleted)IDX_notes_isDeletedonnotes(isDeleted)Expected Impact
Usage
Beta Was this translation helpful? Give feedback.
All reactions