PostgreSQL vacuum_freeze_table_age和vacuum_freeze_min_age理
理解vacuum_freeze_min_age参数: 1. 插入测试数据 postgres=# insert into tb9 select generate_series(1,5),'aa';
INSERT 0 5 postgres=# select xmin,age(xmin),xmax,* from tb9;
xmin | age | xmax | id | name
------+-----+------+----+------
2523 | 1 | 0 | 1 | aa
2523 | 1 | 0 | 2 | aa
2523 | 1 | 0 | 3 | aa
2523 | 1 | 0 | 4 | aa
2523 | 1 | 0 | 5 | aa
(5 rows)
2. 手动设置vacuum_freeze_min_age 值 postgres=# set vacuum_freeze_min_age =10;
SET
这个设置为10的意思是当age(xmin)大于等于10的时候,当执行vacuum操作的时候会将此时表中记录的xmin置为特殊值FrozenXID。 多次执行 select txid_current() 使得事务id增加。 postgres=# select txid_current();
txid_current
--------------
2539
(1 row)
3. 查看数据 postgres=# select xmin,* from tb9;
xmin | age | xmax | id | name ------+-----+------+----+------
2523 | 17 | 0 | 1 | aa
2523 | 17 | 0 | 2 | aa
2523 | 17 | 0 | 3 | aa
2523 | 17 | 0 | 4 | aa
2523 | 17 | 0 | 5 | aa
(5 rows)
看到xmin的事务年龄已经是17。 4. 执行vacuum操作 postgres=# vacuum tb9;
VACUUM
5. 再次查看数据 postgres=# select xmin,* from tb9;
xmin | age | xmax | id | name ------+------------+------+----+------
2 | 2147483647 | 0 | 1 | aa
2 | 2147483647 | 0 | 2 | aa
2 | 2147483647 | 0 | 3 | aa
2 | 2147483647 | 0 | 4 | aa
2 | 2147483647 | 0 | 5 | aa
(5 rows)
freeze后的tuple,xmin 变成了一个FrozenXID,这个XID不参与比较,始终认为这个ID比其他的XID老,所以用 age 去计算始终显示 2147483647 。 说明:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |