Name

journal_mode — Control the creation and cleanup of journal files

Common Usage

PRAGMA journal_mode;
PRAGMA journal_mode = mode;
PRAGMA database.journal_mode;
PRAGMA database.journal_mode = mode;

Description

The journal_mode pragma gets or sets the journal mode. The journal mode controls how the journal file is stored and processed.

Journal files are used by SQLite to roll back transactions due to an explicit ROLLBACK command, or because an unrecoverable error was encountered (such as a constraint violation). Normally, a journal file is required to process any SQL command that causes a modification to a database file. The active lifetime of a journal file extends from the first database modification to the end of the commit process. Journal files are required for both auto-commit transactions (individual SQL commands) as well as explicit transactions. Journal files are a critical part of the transaction process.

There are five supported journal modes:

DELETE

This is the normal behavior. At the conclusion of a transaction, the journal file is deleted.

TRUNCATE

The journal file is truncated to a length of zero bytes. On many filesystems, this is slightly faster than a delete.

PERSIST

The journal file is left in place, but the header is overwritten to indicate the journal is no longer valid. On some filesystems, this can be faster still, as the file blocks remain allocated.

MEMORY

The journal record is held in memory, rather than on disk. This option is extremely fast, but also somewhat ...

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.