真空冻结后是否总是可以更新数据库?

发布于 2025-01-16 04:14:05 字数 124 浏览 3 评论 0原文

如果我对数据库执行VACUUM FREEZE,是否总是可以更新数据库中冻结的行? 或者 VACUUM FREEZE 是否非常危险,因为行变得不可变?这对生产来说将是一场灾难!

If I do a VACUUM FREEZE on a database, is it always possible to update the frozen rows in the database?
Or is VACUUM FREEZE very dangerous because the rows become immutable? That would be a disaster in production!

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

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

发布评论

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

评论(1

┈┾☆殇 2025-01-23 04:14:05

你完全误解了 PostgreSQL 中的“冻结”是什么。它与将行设为只读无关。相反,当一行被冻结时,会在该行上设置一个标志,告诉读者该行是“旧的且可见”,并且读者不必费心检查 xminxmax 该行的系统列,以确定是否可以看到该行。这是必要的,因为存储在 xminxmax 中的事务 ID 一段时间后会“环绕”(它们是 4 字节无符号整数),这会导致数据损坏除非旧行在此之前已被冻结。

除非您知道表中的数据将来不会更新或删除,否则在表上运行 VACUUM (FREEZE) 通常没有意义。否则,冻结稍后将被修改的行将导致不必要的写入(因为冻结行会使缓冲区变脏),这对性能不利。

You completely misunderstand what “freezing” is in PostgreSQL. It has nothing to do with making a row read-only. Rather, when a row is frozen, a flag is set on the row that tells the reader that this row is “old and visible” and the reader shouldn't bother to check the xmin and xmax system columns of the row to determine if it can see the row or not. This is necessary, because the transaction IDs stored in xmin and xmax will “wrap around” after a while (they are 4 byte unsigned integers), and that would cause data corruption unless old rows have been frozen before that happens.

There is usually no point in running VACUUM (FREEZE) on a table unless you know that the data in the table are not going to be updated or deleted in the future. Otherwise, freezing rows that will get modified later will cause unnecessary writes (since freezing a row makes a buffer dirty), which is bad for performance.

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