真空冻结后是否总是可以更新数据库?
如果我对数据库执行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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你完全误解了 PostgreSQL 中的“冻结”是什么。它与将行设为只读无关。相反,当一行被冻结时,会在该行上设置一个标志,告诉读者该行是“旧的且可见”,并且读者不必费心检查
xmin
和xmax
该行的系统列,以确定是否可以看到该行。这是必要的,因为存储在xmin
和xmax
中的事务 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
andxmax
system columns of the row to determine if it can see the row or not. This is necessary, because the transaction IDs stored inxmin
andxmax
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.