Postgresql 中文操作指南

73.7. Heap-Only Tuples (HOT) #

为了允许高并发性,PostgreSQL 使用 multiversion concurrency control (MVCC) 来存储行。然而,对于更新查询来说,MVCC 有一些缺点。具体来说,更新要求将新版本的行添加到表中。这可能还需要为每个更新的行创建新的索引条目,而删除旧版本的行及其索引条目可能会非常耗费资源。

To allow for high concurrency, PostgreSQL uses multiversion concurrency control (MVCC) to store rows. However, MVCC has some downsides for update queries. Specifically, updates require new versions of rows to be added to tables. This can also require new index entries for each updated row, and removal of old versions of rows and their index entries can be expensive.

为了帮助减少更新的开销,PostgreSQL 有一种称为仅堆元组 (HOT) 的优化。当满足以下条件时,可以进行此优化:

To help reduce the overhead of updates, PostgreSQL has an optimization called heap-only tuples (HOT). This optimization is possible when:

在这种情况下,仅堆元组提供了两项优化:

In such cases, heap-only tuples provide two optimizations:

通过减少表的 fillfactor ,您可以增大 HOT 更新具有足够页面空间的可能性。如果您不减少表的 fillfactor ,仍会进行 HOT 更新,因为新行将自然迁移到新页面中,现有页面也有足够的空间供新行版本使用。系统视图 pg_stat_all_tables 允许监控 HOT 更新和非 HOT 更新的发生。

You can increase the likelihood of sufficient page space for HOT updates by decreasing a table’s fillfactor. If you don’t, HOT updates will still happen because new rows will naturally migrate to new pages and existing pages with sufficient free space for new row versions. The system view pg_stat_all_tables allows monitoring of the occurrence of HOT and non-HOT updates.