本文摘自PHP中文网,作者jacklove,侵删。
Insert\delete\update通过ctid定位,并查看该记录xmin\xmax的变化。 Xid:数据库的事务ID;
Xmin:行头部的xid信息,xmin表示插入该记录的事务ID
Xmax:表示删除或lock该记录的事务ID
xid_snapshot:当前集群中为结束的事务
Clog:事务提交状态日志
记录格式的定义:htup_details.h:POSTGRES heap tuple header definitions.
1)查看所有xid相关的函数有哪些,这里需要的是txid_current函数

2)可以看到当前的事务ID
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 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
1 2 3 4 5 6 7 8 9 10 | 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)在另外一个会话查看
1 2 3 4 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)
|
看当前未结束的事务,或未开启的事务

1 2 3 4 5 6 7 8 9 10 11 | postgres=# select * from txid_current_snapshot();
txid_current_snapshot
1684:1684:
(1 row)
postgres=# select * from txid_current();
txid_current
1684
(1 row)
|
记录事务是否提交,在这个文件里面,bit:
1 2 3 | -rw
[pg@localhost pg_clog]$ pwd
/home/pg/data/pg_clog
|
本文介绍了PostgreSQL 版本识别 ,更多相关内容请关注php中文网。
相关推荐:
讲解B/S与C/S究竟是何物
如何通过css3+html5实现纵向菜单
关于HTML5本地存储的相关讲解
以上就是关于PostgreSQL 版本识别 的详解的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
PostgreSQL是什么?
关于PostgreSQL 版本识别 的详解
pg数据库和mysql的区别是什么?
更多相关阅读请进入《PostgreSQL》频道 >>
机械工业出版社
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。
转载请注明出处:木庄网络博客 » 关于PostgreSQL 版本识别 的详解