SQLite DB 中的 -shm 和 -wal 文件 [英] -shm and -wal files in SQLite DB

查看:233
本文介绍了SQLite DB 中的 -shm 和 -wal 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行 wal_checkpoint(FULL) 后使用 cp 命令备份 SQLite DB.DB 正在 WAL 模式下使用,因此我的文件夹中有 -shm 和 -wal 等其他文件.当我运行 wal_checkpoint(FULL) 时,WAL 文件中的更改会提交到数据库.我想知道 -wal 和 -shm 文件是否在运行检查点后被删除.如果不是,那么它们包含什么?

I am taking the backup of SQLite DB using cp commmand 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 waqs wondering whether -wal and -shm files get deelted after running a checkpoint. If not, then what do they contain ?

我知道我的备份过程不好,因为我没有使用 SQLite 备份 API.这是我代码中的一个错误.

任何人都可以建议 -shm 和 -wal 文件在运行检查点后包含哪些内容.

I know my backup process is not good since I am not using SQLite backup APIs. This is a bug in my code.

Can anyone please suggest what content do -shm and -wal files contain after running checkpoint.

提供的任何链接都会有所帮助.

Any link provided would be helpful.

谢谢

推荐答案

在查阅了大量资料后,我相信以下说法是正确的:

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

  1. -shm 文件包含 -wal 文件的索引.-shm 文件提高了读取 -wal 文件时的性能.
  2. 如果 -shm 文件被删除,它会在下次访问数据库时重新创建.
  3. 如果运行checkpoint,可以删除-wal文件.
  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.

要执行安全备份:

  1. 建议您使用 SQLite 备份功能进行备份.SQLite 库甚至可以备份在线数据库.
  2. 如果您不想使用 (1),那么最好的方法是关闭数据库句柄.这确保了数据库文件的干净和一致状态,并删除了 -shm-wal 文件.然后可以使用 cpscp 等进行备份.
  3. 如果打算通过网络传输 SQLite 数据库文件,则应在 checkpoint 之后运行 vacuum 命令.这会消除数据库文件中的碎片,从而减小其大小,从而减少通过网络传输的数据.
  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.

这篇关于SQLite DB 中的 -shm 和 -wal 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆