{"record":{"id":"f8090d467c7bdbb7","repo":"litedb-org/LiteDB","slug":"0-f8090d","errorCode":"0","errorMessage":"Maximum data file size has been reached: {FileHelper.FormatFileSize(_header.Pragmas.LimitSize)}","messagePattern":"Maximum data file size has been reached: (.+?)","errorType":"exception","errorClass":"LiteException","httpStatus":null,"severity":"critical","filePath":"LiteDB/Engine/Services/SnapShot.cs","lineNumber":400,"sourceCode":"\n                    // set header free empty page to next free page\n                    _header.FreeEmptyPageList = free.NextPageID;\n\n                    // clear NextPageID\n                    free.NextPageID = uint.MaxValue;\n\n                    // get pageID from empty list\n                    pageID = free.PageID;\n\n                    // get buffer inside re-used page\n                    buffer = free.Buffer;\n                }\n                else\n                {\n                    // checks if not exceeded data file limit size\n                    var newLength = (_header.LastPageID + 1) * PAGE_SIZE;\n\n                    if (newLength > _header.Pragmas.LimitSize) throw new LiteException(0, $\"Maximum data file size has been reached: {FileHelper.FormatFileSize(_header.Pragmas.LimitSize)}\");\n\n                    var savepoint = _header.Savepoint();\n                    try\n                    {\n                        // increase LastPageID from shared page\n                        pageID = ++_header.LastPageID;\n\n                        // request for a new buffer\n                        buffer = _reader.NewPage();\n                    }\n                    catch\n                    {\n                        // must revert all header content if any error occurs during header change\n                        _header.Restore(savepoint);\n                        throw;\n                    }\n                }\n","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/litedb-org/LiteDB/blob/f906a5f850678719e39a39a006cb66dcae563cfa/LiteDB/Engine/Services/SnapShot.cs#L382-L418","documentation":"Thrown by Snapshot.NewPage when allocating a new data page would make the file length (LastPageID+1)*PAGE_SIZE exceed the LimitSize pragma. LimitSize defaults to long.MaxValue (effectively unlimited), so this only fires when a user explicitly set a limit via connection string (e.g. limitSize=1GB) or the PRAGMA. It triggers only when there are no free/empty pages to recycle, forcing growth.","triggerScenarios":"Continuously inserting data into a database whose connection string set a LimitSize (e.g. 'LimitSize=100MB') once the data file growth exceeds it; also via db.Pragma(\"LIMIT_SIZE\", value) then writing past the cap.","commonSituations":"Embedded/IoT deployments with fixed disk quotas; misconfigured limitSize far below actual data needs; forgetting that LimitSize applies to the data file only and underestimating index overhead; reusing a connection string copied from a constrained sample.","solutions":["Remove or raise the limitSize value in the connection string (omit it for unlimited).","Run db.Pragma(\"LIMIT_SIZE\", long.MaxValue) or a larger byte count at runtime.","Free space by compacting the database: db.Checkpoint() then db.Rebuild() to reclaim empty pages.","Add monitoring of dbSize vs LimitSize so writes are throttled before hitting the wall."],"exampleFix":"// before\nusing var db = new LiteDatabase(\"Filename=app.db;LimitSize=100MB\");\ndb.GetCollection(\"logs\").Insert(hugeDoc); // throws at 100MB\n\n// after - remove cap, or raise it\nusing var db = new LiteDatabase(\"Filename=app.db;LimitSize=1GB\");","handlingStrategy":"validation","validationCode":"// pre-flight free space check before bulk writes\nlong limit = db.Pragma(\"LIMIT_SIZE\");\nlong current = new FileInfo(\"app.db\").Length;\nif (current + estimatedBytes > limit) HandleQuotaExceeded();","typeGuard":null,"tryCatchPattern":"try { collection.InsertBulk(records); }\ncatch (LiteException ex) when (ex.Message.Contains(\"Maximum data file size\")) {\n    // raise LimitSize, Rebuild to reclaim, or shed load\n}","preventionTips":["Omit limitSize unless you genuinely need a cap.","Monitor data file size vs LimitSize in ops dashboards.","Schedule periodic db.Rebuild() to reclaim empty pages."],"tags":["storage","quota","connection-string","pragma"],"backgroundTag":null,"analyzedSha":"f906a5f850678719e39a39a006cb66dcae563cfa","analyzedAt":"2026-08-13T21:56:30.148Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}