// sqlite · wal, redo & durability

synchronous

How often SQLite waits for data to reach the disk (fsync).

デフォルト
2 (FULL)
Range
0 OFF, 1 NORMAL, 2 FULL, 3 EXTRA
Restart needed
いいえ
Default checked on
SQLite 3.5x

何ができるか

FULL (2) syncs at every commit. NORMAL (1) syncs less: in WAL mode it never corrupts the database but a power loss can roll back the last transactions; in rollback-journal mode it carries a small corruption risk on power loss. OFF (0) hands writes to the OS without syncing. EXTRA (3) also syncs the journal's directory.

デフォルト値

2 (FULL). FULL (a stock SQLite 3.5x build), in WAL mode too unless the build sets SQLITE_DEFAULT_WAL_SYNCHRONOUS.

Check the current value

PRAGMA synchronous;

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

Change it

PRAGMA synchronous = NORMAL;   -- 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

Use NORMAL together with WAL for most applications: commits get much faster and the database stays consistent.

What can go wrong

OFF can corrupt the database on power loss or OS crash; NORMAL in WAL mode can lose the most recent commits.

The closest setting on other engines

エンジン設定デフォルトRestart
SQLite synchronous this page 2 (FULL) いいえ
PostgreSQL synchronous_commit on いいえ
MySQL innodb_flush_log_at_trx_commit 1 いいえ
SQL Server DELAYED_DURABILITY DISABLED いいえ

Questions about synchronous

What is the default value of synchronous in SQLite?

2 (FULL). FULL (a stock SQLite 3.5x build), in WAL mode too unless the build sets SQLITE_DEFAULT_WAL_SYNCHRONOUS.

Does changing synchronous 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 synchronous?

Use NORMAL together with WAL for most applications: commits get much faster and the database stays consistent.

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

// one client for every engine

Check synchronous 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.