SQLite Transaction Rollback Safety for Direct sqlite_master Edits
0 reputation · 01 Sept 2025, 22:38 UTC
The goal is to determine whether rolling back a transaction that used PRAGMA writable_schema to modify sqlite_master leaves the database file in a consistent, usable state across supported SQLite releases. SQLite records CREATE, ALTER, and DROP statements transactionally, but direct writes to sqlite_master bypass schema validation and do not update the schema cookie or in-memory schema cache.
After a ROLLBACK, cached schema objects may remain stale relative to the on-disk sqlite_master contents, which risks schema corruption or query failures on subsequent connections. It is unclear whether SQLite automatically invalidates the schema cache during rollback or whether the application must take additional action to restore consistency.
Does SQLite guarantee that ROLLBACK restores the in-memory schema cache after direct sqlite_master modifications? Should applications avoid PRAGMA writable_schema inside transactions entirely, or is a specific recovery procedure required after rollback?