關于PostgreSQL 版本識別 的詳解

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函數

關于PostgreSQL 版本識別 的詳解

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 版本識別 的詳解

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 版本識別 ,更多相關內容請關注php中文網。

相關推薦:

講解B/S與C/S究竟是何物

講解B/S與C/S究竟是何物

講解B/S與C/S究竟是何物

? 版權聲明
THE END
喜歡就支持一下吧
點贊13 分享