litedb-org/LiteDB · critical · LiteException

0

0

Error message

Maximum data file size has been reached: {FileHelper.FormatFileSize(_header.Pragmas.LimitSize)}

What it means

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.

Source

Thrown at LiteDB/Engine/Services/SnapShot.cs:400

                    // set header free empty page to next free page
                    _header.FreeEmptyPageList = free.NextPageID;

                    // clear NextPageID
                    free.NextPageID = uint.MaxValue;

                    // get pageID from empty list
                    pageID = free.PageID;

                    // get buffer inside re-used page
                    buffer = free.Buffer;
                }
                else
                {
                    // checks if not exceeded data file limit size
                    var newLength = (_header.LastPageID + 1) * PAGE_SIZE;

                    if (newLength > _header.Pragmas.LimitSize) throw new LiteException(0, $"Maximum data file size has been reached: {FileHelper.FormatFileSize(_header.Pragmas.LimitSize)}");

                    var savepoint = _header.Savepoint();
                    try
                    {
                        // increase LastPageID from shared page
                        pageID = ++_header.LastPageID;

                        // request for a new buffer
                        buffer = _reader.NewPage();
                    }
                    catch
                    {
                        // must revert all header content if any error occurs during header change
                        _header.Restore(savepoint);
                        throw;
                    }
                }

View on GitHub (pinned to f906a5f850)

Solutions

  1. Remove or raise the limitSize value in the connection string (omit it for unlimited).
  2. Run db.Pragma("LIMIT_SIZE", long.MaxValue) or a larger byte count at runtime.
  3. Free space by compacting the database: db.Checkpoint() then db.Rebuild() to reclaim empty pages.
  4. Add monitoring of dbSize vs LimitSize so writes are throttled before hitting the wall.

Example fix

// before
using var db = new LiteDatabase("Filename=app.db;LimitSize=100MB");
db.GetCollection("logs").Insert(hugeDoc); // throws at 100MB

// after - remove cap, or raise it
using var db = new LiteDatabase("Filename=app.db;LimitSize=1GB");
Defensive patterns

Strategy: validation

Validate before calling

// pre-flight free space check before bulk writes
long limit = db.Pragma("LIMIT_SIZE");
long current = new FileInfo("app.db").Length;
if (current + estimatedBytes > limit) HandleQuotaExceeded();

Try / catch

try { collection.InsertBulk(records); }
catch (LiteException ex) when (ex.Message.Contains("Maximum data file size")) {
    // raise LimitSize, Rebuild to reclaim, or shed load
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of litedb-org/LiteDB@f906a5f850 (2026-08-13). Data as JSON: /api/errors/f8090d467c7bdbb7. Report an issue: GitHub.