删除多条记录后如何优化表

发布于 2024-08-09 22:04:48 字数 82 浏览 3 评论 0原文

我从表中删除了许多记录,但数据库大小(Firebird)保持不变。我该如何减少它?

我正在 PostgreS 中寻找类似于真空的东西。

I deleted many records from my table but the DB size (Firebird) left the same. How do I decrease it?

I am looking for something similar to vacuum in PostgreS.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

野侃 2024-08-16 22:04:48

这是火鸟的众多痛苦之一。
最好且唯一有效且正确的方法 - 使用 gbak 备份/恢复数据库

This is one of many pains of firebird.
Best and only effective and right way to do this - backup/restore your database using gbak

德意的啸 2024-08-16 22:04:48

Firebird 有时会进行扫描,从索引等中删除记录,并重新获得空间以供其他用途。换句话说,一旦扫描运行,您将获得与数据库文件较小时相同的性能。如果您想要这样做,您可以强制执行立即扫描。

但是,无论如何,实际数据库的大小都不会缩小,除非您进行备份和恢复。如果大小是一个问题,请使用 gbak 的 -USE_ALL_SPACE 参数,它将阻止为将来的记录保留空间,这将产生较小的数据库。

Firebird will occasionally run a sweep to remove the records from indexes etc., and regain the space for other use. In other words, as soon as the sweep has run, you will have the same performance as if the database file was smaller. You can enforce an immediate sweep, if that is what you are trying to do.

However, the size of the actual database will not shrink, no matter what, except if you do a backup and restore. If size is a problem, use the -USE_ALL_SPACE parameter for gbak, it will prevent that space is being reserved for future records, which will yield a smaller database.

饭团 2024-08-16 22:04:48

来自官方常见问题解答

许多用户想知道为什么他们在使用时无法收回磁盘空间
从数据库中删除大量记录。

原因是这是一项昂贵的操作,需要
大量磁盘写入和内存 - 就像重新碎片化一样
硬盘分区。使用的数据库部分(页面)
这些数据被标记为空,Firebird 下次将重用它们
它需要写入新数据。

如果磁盘空间对您来说至关重要,您可以通过以下方式取回空间
进行备份然后恢复。由于您正在执行备份
立即恢复,明智的做法是使用“禁止垃圾收集”
或“不使用垃圾收集”开关(gbak 中的 -G),这将使
备份速度更快。垃圾收集用于清理您的
数据库,并且由于它是一项维护任务,因此通常一起完成
带有备份(因为备份必须遍历整个数据库)。
但是,您很快就会放弃该数据库文件,并且没有
需要清理它。

From the official faq

Many users wonder why they don't get their disk space back when they
delete a lot of records from database.

The reason is that it is an expensive operation, it would require a
lot of disk writes and memory - just like doing refragmentation of
hard disk partition. The parts of database (pages) that were used by
such data are marked as empty and Firebird will reuse them next time
it needs to write new data.

If disk space is critical for you, you can get the space back by
doing backup and then restore. Since you're doing the backup to
restore right away, it's wise to use the "inhibit garbage collection"
or "don't use garbage collection" switch (-G in gbak), which will make
backup go A LOT FASTER. Garbage collection is used to clean up your
database, and as it is a maintenance task, it's often done together
with backup (as backup has to go throught entire database anyway).
However, you're soon going to ditch that database file, and there's no
need to clean it up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文