What guarantees SQLite provides for recovery after an interrupted schema upgrade?
0 reputation · 13 Aug 2022, 02:02 UTC
Goal: ensure that a SQLite database can be returned to a consistent, usable state after a process crashes while a schema‑changing statement (e.g., ALTER TABLE, CREATE INDEX) is being committed.
SQLite relies on its rollback journal or Write‑Ahead Log (WAL) to undo partial writes, and the PRAGMA integrity_check procedure can verify B‑tree and index consistency after a disruptive event. However, it is unclear whether these mechanisms guarantee a full rollback of DDL changes, whether integrity_check can detect all corruptions without shutting down the database, and whether a concurrent VACUUM INTO operation can safely produce a clean copy while the journal or WAL files remain present.
Does the rollback journal/WAL guarantee that a partially applied ALTER TABLE is fully rolled back after a crash? Can PRAGMA integrity_check reliably detect corruption caused by an interrupted upgrade without requiring a shutdown? Is it safe to run VACUUM INTO on the main database file while the -wal and -shm files are present to obtain a clean copy for recovery?