// sqlite · memory

soft_heap_limit

Advisory ceiling on the heap memory SQLite may use across every connection in the process.

默认
0 (no limit)
Range
0 or more bytes
Restart needed
否
Default checked on
SQLite 3.5x

作用

The limit is process wide, not per connection. As usage climbs toward it, SQLite shrinks page caches to stay under. It is advisory: SQLite will cross the limit rather than fail a query with SQLITE_NOMEM. Setting 0 removes the limit; values that are not non-negative integers leave it unchanged.

默认值

0 (no limit). 0 (a stock SQLite 3.5x build), meaning the limit is disabled.

Check the current value

PRAGMA soft_heap_limit;

SELECT * FROM pragma_soft_heap_limit;   -- table-valued form, usable in queries

Change it

PRAGMA soft_heap_limit = 268435456;   -- this connection only

No restart. It applies at once to the connection that runs it and is lost when that connection closes, so set it every time a connection opens.

When to change it

In one process that hosts many connections on a memory-constrained device, to tell SQLite to give page-cache memory back as usage grows.

What can go wrong

It bends instead of holding: a query that genuinely needs the memory still gets it, so treat this as a hint for cache trimming. One connection's PRAGMA moves the ceiling for every connection in the process.

Questions about soft_heap_limit

What is the default value of soft_heap_limit in SQLite?

0 (no limit). 0 (a stock SQLite 3.5x build), meaning the limit is disabled.

Does changing soft_heap_limit require a restart?

No. No restart. It applies at once to the connection that runs it and is lost when that connection closes, so set it every time a connection opens.

When should I change soft_heap_limit?

In one process that hosts many connections on a memory-constrained device, to tell SQLite to give page-cache memory back as usage grows.

Back to all SQLite settings, or check the SQLite manual for every option.

// one client for every engine

Check soft_heap_limit on your own server

SQLly runs the query above against SQLite and the other engines in this reference, from one desktop app on macOS, Windows and Linux.

本页文字和数据: CC BY 4.0,请注明出处 SQLly (sqlly.app)。 代码和 SQL 片段: MIT. 许可详情