@H_403_1@Insert\delete\update通过ctid定位,并查看该记录xmin\xmax的变化。
@H_403_1@Xid:数据库的事务ID;
@H_403_1@Xmin:行头部的xid信息,xmin表示插入该记录的事务ID
@H_403_1@Xmax:表示删除或lock该记录的事务ID
@H_403_1@xid_snapshot:当前集群中为结束的事务
@H_403_1@Clog:事务提交状态日志
@H_403_1@记录格式的定义:htup_details.h:POSTGRES heap tuple header definitions.
@H_403_1@
@H_403_1@1)查看所有xid相关的函数有哪些,这里需要的是txid_current函数
@H_403_1@
@H_403_1@
@H_403_1@2)可以看到当前的事务ID
@H_403_1@postgres=# select * from txid_current();
@H_403_1@txid_current
@H_403_1@--------------
@H_403_1@1676
@H_403_1@(1 row)
@H_403_1@3)进行一次insert后,看事务ID已经+1
@H_403_1@postgres=# insert into tt values(1);
@H_403_1@INSERT 0 1
@H_403_1@postgres=# select ctid,xmin,xmax,cmin,cmax,id from tt;
@H_403_1@ctid | xmin | xmax | cmin | cmax | id
@H_403_1@-------+------+------+------+------+----
@H_403_1@(0,1) | 1677 | 0 | 0 | 0 | 1
@H_403_1@(1 row)
@H_403_1@4)开启一个事务后,进行update
@H_403_1@postgres=# begin;
@H_403_1@BEGIN
@H_403_1@postgres=# update tt set id=3;
@H_403_1@UPDATE 1
@H_403_1@postgres=# select ctid,2) | 1678 | 0 | 0 | 0 | 3
@H_403_1@(1 row)
@H_403_1@5)在另外一个会话查看
@H_403_1@postgres=# select ctid,1) | 1677 | 1678 | 0 | 0 | 1
@H_403_1@(1 row)
@H_403_1@
@H_403_1@ @H_403_1@看当前未结束的事务,或未开启的事务 @H_403_1@ @H_403_1@ @H_403_1@postgres=# select *from txid_current_snapshot(); @H_403_1@txid_current_snapshot @H_403_1@----------------------- @H_403_1@1684:1684: @H_403_1@(1 row) @H_403_1@postgres=# select * from txid_current(); @H_403_1@txid_current @H_403_1@-------------- @H_403_1@1684 @H_403_1@(1 row) @H_403_1@记录事务是否提交,在这个文件里面,bit: @H_403_1@-rw-------. 1 pg pg 8192 Jun 10 04:19 0000 @H_403_1@[pg@localhost pg_clog]$ pwd @H_403_1@/home/pg/data/pg_clog
@H_403_1@ @H_403_1@看当前未结束的事务,或未开启的事务 @H_403_1@ @H_403_1@ @H_403_1@postgres=# select *from txid_current_snapshot(); @H_403_1@txid_current_snapshot @H_403_1@----------------------- @H_403_1@1684:1684: @H_403_1@(1 row) @H_403_1@postgres=# select * from txid_current(); @H_403_1@txid_current @H_403_1@-------------- @H_403_1@1684 @H_403_1@(1 row) @H_403_1@记录事务是否提交,在这个文件里面,bit: @H_403_1@-rw-------. 1 pg pg 8192 Jun 10 04:19 0000 @H_403_1@[pg@localhost pg_clog]$ pwd @H_403_1@/home/pg/data/pg_clog