Skip to content

SQLite Optimizing

TL;DR

PRAGMA journal_mode = WAL;
PRAGMA busy_timeout = 5000;
PRAGMA synchronous = NORMAL;
PRAGMA cache_size = 1000000000;
PRAGMA foreign_keys = true;
PRAGMA temp_store = memory;

Use BEGIN IMMEDIATE transactions.

writeDB.SetMaxOpenConns(1)
readDB.SetMaxOpenConns(max(4, runtime.NumCPU()))

Use STRICT tables.

Reference

  • https://kerkour.com/sqlite-for-servers
  • https://use.expensify.com/blog/scaling-sqlite-to-4m-qps-on-a-single-server
Feedback