ablog

不器用で落着きのない技術者のメモ

(Aurora) PostgreSQL の Transaction ID は2億に達するとAUTO VACUUM で自動回収される

(Aurora) PostgreSQL の Transaction ID(XID) は AUTO VACUUM で autovacuum_freeze_max_age (デフォルトは2億)に達すると自動的に回収される。
以下は実際の CloudWatch メトリクスの MaximumUsedTransactionIDs のグラフの推移。

  • XID が2億(200M)に達すると回収されて下がっている。
  • Statistics は Maximum を選択する(Sum にすると5分間の合計値になるため)


CloudWatch アラームで監視する場合は 3 億くらいにしておくとちょうどえぇかと思う。

環境

  • Aurora PostgreSQL 4 (PostgreSQL 12.6)
  • パラメータグループで autovacuum_freeze_max_age はデフォルトのまま

参考

autovacuumの強制実行
データベース内で一番古いトランザクションIDと現在のトランザクションIDとの差(ageと言います)が2億個(autovacuum_freeze_max_ageパラメーターのデフォルト値)を超えるとautovacuumが強制的に実行され、想定外にデータベースの負荷が高くなることがあります。なお、利用できる残りのトランザクションIDの数が少なくなると、新たなトランザクションIDの割り振りが抑止され、インスタンスがエラーで操作できなくなることもあります。

パフォーマンスチューニング9つの技 ~「基盤」について~|PostgreSQLインサイド : 富士通

autovacuum_freeze_max_age (integer)
Specifies the maximum age (in transactions) that a table's pg_class.relfrozenxid field can attain before a VACUUM operation is forced to prevent transaction ID wraparound within the table. Note that the system will launch autovacuum processes to prevent wraparound even when autovacuum is otherwise disabled.

Vacuum also allows removal of old files from the pg_xact subdirectory, which is why the default is a relatively low 200 million transactions. This parameter can only be set at server start, but the setting can be reduced for individual tables by changing table storage parameters. For more information see Section 24.1.5.

PostgreSQL: Documentation: 12: 19.10. Automatic Vacuuming