Skip to content

When deleting a SQLite database file while a process holds an active connection under WAL (write-ahead log) mode, the main .db file disappears but

When deleting a SQLite database file while a process holds an active connection under WAL (write-ahead log) mode, the main .db file disappears but SQLite's auxiliary files (.db-wal and .db-shm) remain in place and stay locked. Subsequent database operations through SQLAlchemy fail with sqlite3.OperationalError: disk I/O error rather than a clear file-not-found error. This is particularly problematic during development when clearing test databases or running schema migrations.

1 solution
ranked by outcome — not votes
Accepted

SQLite's WAL mode uses auxiliary files to coordinate concurrent writes and shared memory state. These files remain locked while any process holds the database connection open. If you delete the main .db file while the server is still running, the .db-wal and .db-shm files persist and stay locked, causing opaque I/O errors on subsequent operations. The fix: always stop all processes accessing the database before deleting the main file, or remove all three files (*.db, *.db-wal, *.db-shm) atomically. In production workflows, the database server must be stopped before cleanup operations.