Insert\delete\update通过ctid定位,并查看该记录xmin\xmax的变化。

Xid:数据库的事务ID

Xmin:行头部的xid信息,xmin表示插入该记录的事务ID

Xmax:表示删除或lock该记录的事务ID

xid_snapshot:当前集群中为结束的事务

Clog:事务提交状态日志

记录格式的定义:htup_details.hPOSTGRES heap tuple header definitions.

1)查看所有xid相关的函数有哪些,这里需要的是txid_current函数

关于PostgreSQL 版本识别 的详解-LMLPHP

2)可以看到当前的事务ID

postgres=# select * from txid_current();
 txid_current
--------------
         1676
(1 row)
 
3)进行一次insert后,看事务ID已经+1
postgres=# insert into tt values(1);
INSERT 0 1
postgres=# select ctid,xmin,xmax,cmin,cmax,id from tt;
 ctid  | xmin | xmax | cmin | cmax | id
-------+------+------+------+------+----
 (0,1) | 1677 |    0 |    0 |    0 |  1
(1 row)
登录后复制

4)开启一个事务后,进行update

postgres=# begin;
BEGIN
 
postgres=# update tt set id=3;
UPDATE 1
postgres=# select ctid,xmin,xmax,cmin,cmax,id from tt;
 ctid  | xmin | xmax | cmin | cmax | id
-------+------+------+------+------+----
 (0,2) | 1678 |    0 |    0 |    0 |  3
(1 row)
登录后复制

5)在另外一个会话查看

postgres=#  select ctid,xmin,xmax,cmin,cmax,id from tt;
 ctid  | xmin | xmax | cmin | cmax | id
-------+------+------+------+------+----
 (0,1) | 1677 | 1678 |    0 |    0 |  1
(1 row)
登录后复制


看当前未结束的事务,或未开启的事务

关于PostgreSQL 版本识别 的详解-LMLPHP

postgres=# select *from txid_current_snapshot();
 txid_current_snapshot
-----------------------
 1684:1684:
(1 row)
 
postgres=# select * from txid_current();
 txid_current
--------------
         1684
(1 row)
登录后复制

记录事务是否提交,在这个文件里面,bit

-rw-------. 1 pg pg 8192 Jun 10 04:19 0000
[pg@localhost pg_clog]$ pwd
/home/pg/data/pg_clog
登录后复制

本文介绍了PostgreSQL 版本识别 ,更多相关内容请关注Work网。

相关推荐:

讲解B/S与C/S究竟是何物

如何通过css3+html5实现纵向菜单

关于HTML5本地存储的相关讲解

以上就是关于PostgreSQL 版本识别 的详解的详细内容,更多请关注Work网其它相关文章!

08-30 06:02