我正在使用一个 sqlite3 数据库,可以想象它会变得非常大。存储空间是一个问题,因此我考虑将 auto_vacuum pragma 设置为 on,以便实际释放已删除行占用的空间,而不是仅仅标记为可重复使用。
在我的场景中,数据库可能每月增长数百 MB,而超过 6 个月的行会以粒度方式衰减。这是通过一个作业队列实现的,该队列随机执行除当前任务外删除 nn 个最旧记录的任务,其中 nn 由队列中有多少个高优先级任务决定。
我希望这可以避免必须编写导致长时间 RW 饥饿(以分钟为单位,删除行然后运行 VACUUM)的维护作业,而同样的情况一次可以实现几个 MS。这可能意味着“旧”行在数据库中的保留时间比其他情况下多几天,但这是一个可以接受的权衡。
我的问题是,根据您的经验(也许还有意见),根据我的描述,打开 auto_vacuum 是否是一种 Not Acceptable 妥协?如果是这样,原因是什么?我没有广泛使用 sqlite3,更不用说它提供的用于调整的各种 pragma,所以我希望在做出判断之前征求我所缺乏的经验,我可能会在几个月后后悔 :)
我正在使用 C 接口(interface),如果它有任何不同的话。
最佳答案
Liferea 开发人员 explains why :
The problem with it is that it also takes very long. With a 50MB DB file I experienced a runtime of over 1 minute. This is why this can be only a tool for experienced users that know how to do it manually knowing what to expect. For executing such a long term operation automatically on runtime would surely be unacceptable to the unsuspecting user. Also there is no good way how to decide when to do a VACUUM to save disk space and improve performance.
关于c - sqlite3 auto_vacuum pragma 有缺点吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4151872/