// SQLite error reference

SQLITE_NOMEM: out of memory

SQLite couldn't allocate memory it needed to continue. Usually the process is out of memory, or a heap limit was set too low.

Result code
SQLITE_NOMEM
Name
7
Category
Primary result codes
Error message
out of memory

What it means

SQLITE_NOMEM (7) means an internal call to sqlite3_malloc() or sqlite3_realloc() failed when the memory was required to continue. SQLite is designed to fail cleanly here, rolling back the statement without corrupting the database.

Common causes

  • The process or container hit its memory limit.
  • A soft or hard heap limit set with sqlite3_soft_heap_limit64() or sqlite3_hard_heap_limit64(), or PRAGMA hard_heap_limit.
  • A query building a huge in-memory result: a sort or GROUP BY without an index, or temp_store = MEMORY with a large intermediate result.
  • A very large cache_size setting.

How to fix it

  1. Check memory limits on the process or container, and any heap limit the application sets.

    PRAGMA soft_heap_limit;
    PRAGMA hard_heap_limit;
  2. Let large temporary results go to disk instead of memory, and reduce the page cache if it is very large.

    PRAGMA temp_store = FILE;
    PRAGMA cache_size = -64000;  -- about 64 MB
  3. Add indexes so sorts and groupings don't need to hold everything in memory.

Related errors

More primary result codes errors

The code and message text are from the SQLite result and error codes documentation. Browse the full SQLite error list or search every database error.

// fewer errors, faster fixes

Work on SQLite in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQLite and the other databases you use.