We’re using Sqlite3 as an embedded database on a C++ based project. The process that uses the sqlite3 interface (the one that actually commits log records) appears to expand its heap memory as the database increases in size.
The heap memory expansion definitely is directly related to the size of database (evidence: if the “insert-to-database” line is commented out the expansion never takes place AND if log wrapping is enabled, when the database starts to wrap the expansion stops occurring as if it’s maxed out).
We’re on a unix-like OS.
Does anyone know if SQLITE3 performs some kind of caching we could disable, if UNIX may be doing this itself, or if it is a problem at all necessarily? The worry here is obviously that heap memory could be exhausted, causing our system to crash.
I have seen the odd reference to UNIX caching things itself and releasing the cache-related memory when it’s required otherwise, but I don’t know enough about the subject to be confident about that being true. I haven’t successfully found anything relevant (that I understand) in SQLITE3 documentation.
I determined after a few days that you can use a pragma upon database creation or prior to connection opening to mitigate this issue. I’ll post it as an accepted answer since no-one even commented on this question since its posting.
Set this through the sqlite3 interface and set it to 0 or a number you like more.
to stop the process memory from growing according to the database size. Apparently, even though there are “default” caching limits, they either were disabled or just not working in our implementation – possibly due to compilation options used while cross-compiling sqlite3. Setting the pragma makes it properly enforce the limits to stop the process size growth.
Here’s a reference for more info:
http://www.sqlite.org/pragma.html#pragma_cache_size