← Graph

SQLite Single-Writer Concurrency Trade-off

concept 1 connections

In WAL mode SQLite allows any number of concurrent readers, but only one writer may hold a reserved lock at a time. Rails' immediate-transaction mode acquires this lock on BEGIN. For typical short Active Record updates on NVMe SSDs this is fine, but long-running transactions (e.g. wrapping an external HTTP call, or a migration that updates many rows) lock the whole database for the duration. Mitigations: reorder operations to do external calls outside transactions, use raw SQL, disable the wrapping transaction on long migrations, or move data migrations into rake tasks. Contrast with Postgres's MVCC row-level locking.

category
pattern
about
SQLite Single-Writer Concurrency Trade-off concept
Discussed in depth with migration-specific mitigations.

Provenance

Read by
2 extractions