// 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.