加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

PostgreSQL 版本识别

发布时间:2020-12-13 16:37:38 所属栏目:百科 来源:网络整理
导读:Insertdeleteupdate 通过 ctid 定位,并查看该记录 xminxmax 的变化。 Xid :数据库的事务 ID ; Xmin :行头部的 xid 信息, xmin 表示插入该记录的事务 ID Xmax :表示删除或 lock 该记录的事务 ID xid_snapshot :当前集群中为结束的事务 Clog :事务

Insertdeleteupdate通过ctid定位,并查看该记录xminxmax的变化。

Xid:数据库的事务ID

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

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

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

Clog:事务提交状态日志

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

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

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,2) | 1678 | 0 | 0 | 0 | 3

(1 row)

5)在另外一个会话查看

postgres=# select ctid,1) | 1677 | 1678 | 0 | 0 | 1

(1 row)


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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读