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

  • Mastering PostgreSQL 9.6
  • Hans Jurgen Schonig
  • 369字
  • 2021-07-09 19:57:14

Digging into transaction wraparound-related issues

There are two more settings in postgresql.conf that are quite important to understand:

autovacuum_freeze_max_age = 200000000 
autovacuum_multixact_freeze_max_age = 400000000

To understand the overall problem, it is important to understand how PostgreSQL handles concurrency. The PostgreSQL transaction machinery is based on the comparison of transaction IDs and the states transactions are in.

An example: If I am transaction ID 4711 and if you happen to be 4712, I won't see you because you are still running. If I am transaction ID 4711 but you are transaction ID 3900, I will see you provided you have committed; and I will ignore you if you failed.

The trouble is as follows: transaction IDs are finite, not unlimited. At some point, they will start to wrap around. In reality, this means that transaction number 5 might actually be after transaction number 800,000,000. How does PostgreSQL know what was first? It does so by storing a watermark. At some point, those watermarks will be adjusted, and this is exactly when VACUUM starts to be relevant. By running VACUUM (or autovacuum), you can ensure that the watermark is adjusted in a way that there are always enough future transaction IDs left to work with.

Not every transaction will increase the transaction ID counter. As long as a transaction is still reading, it will only have a virtual transaction ID. This ensures that transaction IDs are not burned too quickly.

autovacuum_freeze_max_age defines the maximum number of transactions (age) that a table's pg_class.relfrozenxid field can attain before a VACUUM operation is forced to prevent transaction ID wraparound within the table. This value is fairly low because it also has an impact on clog cleanup (the clog or commit log is a data structure that stores 2 bits per transaction, which indicate whether a transaction is running, aborted, committed, or still in a subtransaction).

The autovacuum_multixact_freeze_max_age configures the maximum age (in multixacts) that a table's pg_class.relminmxid field can attain before a VACUUM operation is forced to prevent multixact ID wraparound within the table. Freezing tuples is an important performance issue and there will be more about this process in Chapter 6, Optimizing for Good Query Performance, which is about query optimization.

主站蜘蛛池模板: 台州市| 盐池县| 柳州市| 兴城市| 黄梅县| 石狮市| 松江区| 盐池县| 民权县| 闻喜县| 台北县| 邛崃市| 孙吴县| 宁化县| 青龙| 苍山县| 库车县| 永新县| 固原市| 太原市| 信阳市| 茶陵县| 宽甸| 阿克| 辰溪县| 新巴尔虎左旗| 轮台县| 通海县| 介休市| 漳浦县| 永嘉县| 杨浦区| 洛扎县| 玛纳斯县| 宣化县| 黄骅市| 游戏| 读书| 秦安县| 蒙自县| 浦县|