知识点
-
MVCC
PostgreSQL使用(Multiversion Concurrency Control,MVCC)多版本并发控制来维护数据一致性。
https://www.postgresql.org/docs/13/mvcc-intro.html -
表的隐藏列
tableoid: 行所在表的 OID,tableoid 可以对被连接oid的列pg_class来获得表名。
ctid: 每个行记录在其表中的物理位置标识,(Data block, Row)
xmin: insert 事务ID
xmax: delete 事务ID -
pg_current_xact_id 函数,取代 txid_current()函数,返回当前交易的 ID。
示例
postgis=# create table t1(id int);
postgis=# insert into t1 values(1);
postgis=# select tableoid, ctid, xmin, xmax, cmin, cmax, id from t1;
tableoid | ctid | xmin | xmax | cmin | cmax | id
----------+-------+------+------+------+------+----
26081 | (0,1) | 4688 | 0 | 0 | 0 | 1
-- tableoid: 行所在表的 OID,tableoid可以对被连接oid的列pg_class来获得表名。
postgis=# select oid, relfilenode, relname from pg_catalog.pg_class where oid=26081;
oid | relfilenode | relname
-------+-------------+---------
26081 | 26081 | t1
-- 获取表的物理位置
postgis=# select pg_relation_filepath('t1');
pg_relation_filepath
----------------------
base/18670/26081
INSERT

xmin 就是 insert 这条数据时的事务ID,xmax默认为0。
DELETE

xmax 就是 insert 这条数据时的事务ID
UPDATE

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




