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

  • Mastering PostgreSQL 12
  • Hans Jürgen Sch?nig
  • 264字
  • 2021-08-20 10:00:24

Limiting transactions by 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's config file, postgresql.conf, which has all of the configuration parameters that are needed for this:

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 that it cannot be set inside a session. By limiting the age of a transaction, the risk of insanely long transactions will decrease drastically.

主站蜘蛛池模板: 噶尔县| 东兴市| 水城县| 社会| 盐池县| 西乡县| 长沙市| 奉贤区| 兰坪| 商水县| 拉孜县| 南靖县| 沐川县| 伊金霍洛旗| 广宁县| 北京市| 神农架林区| 镇安县| 余江县| 惠东县| 白银市| 屏南县| 新田县| 台南市| 郯城县| 西平县| 池州市| 桂东县| 惠东县| 桓仁| 左贡县| 洛南县| 云龙县| 九龙县| 揭东县| 凤阳县| 巴林右旗| 商都县| 广平县| 景洪市| 兴海县|