-shm and -wal files in SQLite DB

泄露秘密 提交于 2019-12-02 20:54:57
Manik Sidana

After searching through numerous sources, I believe the following to be true:

  1. The -shm file contains an index to the -wal file. The -shm file improves performance when reading the -wal file.
  2. If the -shm file gets deleted, it get created again during next database access.
  3. If checkpoint is run, the -wal file can be deleted.

To perform safe backups:

  1. It is recommended that you use SQLite backup functions for making backups. SQLite library can even make backups of an online database.
  2. If you don't want to use (1), then the best way is to close the database handles. This ensures a clean and consistent state of the database file, and deletes the -shm and -wal files. A backup can then be made using cp, scp etc.
  3. If the SQLite database file is intended to be transmitted over a network, then the vacuum command should be run after checkpoint. This removes the fragmentation in the database file thereby reducing its size, so you transfer less data through network.

The -shm file does not contain any permanent data.

When the last connection is closed, the database is automatically checkpointed, and the -wal file is then deleted. This implies that after a checkpoint, and if no other connections exist, the -wal file does not contain any important data.

If possible, you should close the connection before taking the backup.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!