I am taking the backup of SQLite DB using cp command after running wal_checkpoint(FULL). The DB is being used in WAL mode so there are other files like -shm and -wal in my folder. When I run wal_checkpoint(FULL), the changes in WAL file get committed to the database. I was wondering whether -wal and -shm files get deleted after running a checkpoint. If not, then what do they contain ?
I know my backup process is not good since I am not using SQLite backup APIs. This is a bug in my code.
After searching through numerous sources, I believe the following to be true:
-shm
file contains an index to the -wal
file. The -shm
file improves performance when reading the -wal
file.-shm
file gets deleted, it get created again during next database access.checkpoint
is run, the -wal
file can be deleted.To perform safe backups:
-shm
and -wal
files. A backup can then be made using cp
, scp
etc.checkpoint
. This removes the fragmentation in the database file thereby reducing its size, so you transfer less data through network.