Name

temp_store — Control the temporary storage mode

Common Usage

PRAGMA temp_store;
PRAGMA temp_store = mode;

Description

The temp_store pragma gets or sets the storage mode used by temporary database files. This pragma does not affect journal files.

SQLite supports the following storage modes:

ModeMeaning
0 or DEFAULTUse compile-time default. Normally FILE.
1 or FILEUse file-based storage
2 or MEMORYUse memory-based storage

The set mode can be either the name or the integer equivalent. The returned value will always be an integer.

Memory-based storage will make temporary databases equivalent to in-memory databases. File-based databases will initially be in-memory databases, until they outgrow the page cache. This means that many “file-based” temporary databases never actually make it into a file.

Changing the mode will cause all temporary databases (and the data they contain) to be deleted.

In some cases, this pragma can be disabled with the SQLITE_TEMP_STORE compile-time directive. Possible compile-time values include:

ValueMeaning
0Always use files, ignore pragma
1Allow pragma, default to files
2Allow pragma, default to memory
3Always use memory, ignore pragma

The default value is 1. Temporary storage defaults to using files, but allows the temp_store pragma to override that choice.

Get Using SQLite now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.