Python in-memory database overflow
<p>I couldn't find an answer online, so here it goes. I'm developing a SAAS that creates a temporary in-memory SQLITE3 database on the cloud for each user. The databases will not be stored, hence they are in-memory:</p>

<pre><code>import sqlite3
conn = sqlite3.connect(':memory:')
</code></pre>

<p>My question is regarding scalability. Worst case scenario there are thousands of users each creating GB sized databases all at the same time. What is the default behavior of SQLITE3 when it runs out of memory? Will it write additional databases to disk? Will it just crash?</p>

<p>I realize this is also a function of how the SAAS SERVER is configured, but my question lies only with the memory issue. </p>

<p>This <a href="https://www.sqlite.org/inmemorydb.html" rel="nofollow">documentation page</a> reads:</p>

<blockquote>
  <p>The sole difference [between a temporary and an in-memory database] is that a ":memory:" database must remain in memory at all times whereas parts of a temporary database might be flushed to disk if database becomes large or if SQLite comes under memory pressure.</p>
</blockquote>

<p>This means that if SQLite runs out of memory then you'll probably hit your operating system's error codes.</p>

<p>The database may be swapped to disk by the OS even if the ram is consumed, though.</p>

<p>I'd advise to use a temporary database instead as described on the same documentation page if you're that worried, so if you run out of ram, SQLite will be able to flush them to disk.</p>

python database memory sqlite3