官术网_书友最值得收藏!

  • Mastering PostgreSQL 10
  • Hans Jürgen Sch?nig
  • 242字
  • 2021-06-30 19:03:52

Making use of snapshot too old

VACUUM does a good job and it will reclaim free space as needed. However, when can VACUUM actually clean out rows and turn them into free space? The rule is this: if a row cannot be seen by anybody anymore, it can be reclaimed. In reality, this means that everything that is no longer seen even by the oldest active transaction can be considered to be really dead.

This also implies that really long transactions can postpone cleanup for quite some time. The logical consequence is table bloat. Tables will grow beyond proportion and performance will tend to go downhill. Fortunately, starting with PostgreSQL 9.6, the database has a nice feature that allows the administrator to intelligently limit the duration of a transaction. Oracle administrators will be familiar with the snapshot too old error; since PostgreSQL 9.6, this error message is also available. However, it is more of a feature than an unintended side-effect of bad configuration (which it actually is in Oracle).

To limit the lifetime of snapshots, you can make use of a setting in postgresql.conf:

old_snapshot_threshold = -1 
         # 1min-60d; -1 disables; 0 is immediate 

If this variable is set, transactions will fail after a certain amount of time. Note that this setting is on an instance level and it cannot be set inside a session. By limiting the age of a transaction, the risk of insanely long transactions will decrease drastically.

主站蜘蛛池模板: 霍林郭勒市| 赫章县| 枝江市| 江津市| 察雅县| 达拉特旗| 贵港市| 保定市| 临泉县| 南溪县| 西城区| 霍林郭勒市| 浠水县| 牟定县| 繁峙县| 辉县市| 玛曲县| 墨竹工卡县| 东海县| 乐业县| 武穴市| 南陵县| 庐江县| 泰宁县| 高尔夫| 札达县| 深圳市| 平邑县| 长乐市| 东乌珠穆沁旗| 兰溪市| 金秀| 涪陵区| 安福县| 黔江区| 疏勒县| 舟山市| 合山市| 兴安盟| 桂阳县| 屏山县|