日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

postgresql 数据库表隐藏列 oid、tableoid、ctid、xmin、xmax、cmin、cmax

發布時間:2024/3/13 数据库 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 postgresql 数据库表隐藏列 oid、tableoid、ctid、xmin、xmax、cmin、cmax 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

os: centos 7.4
db: postgresql 10.11

oid、tableoid、ctid、xmin、xmax、cmin、cmax 這些都是 postgresql 數據庫表的隱藏列.

起著不同的作用.

版本

# cat /etc/centos-release CentOS Linux release 7.4.1708 (Core) # # # yum list installed |grep -i postgresql postgresql10.x86_64 10.11-2PGDG.rhel7 @pgdg10 postgresql10-contrib.x86_64 10.11-2PGDG.rhel7 @pgdg10 postgresql10-debuginfo.x86_64 10.11-2PGDG.rhel7 @pgdg10 postgresql10-devel.x86_64 10.11-2PGDG.rhel7 @pgdg10 postgresql10-docs.x86_64 10.11-2PGDG.rhel7 @pgdg10 postgresql10-libs.x86_64 10.11-2PGDG.rhel7 @pgdg10 postgresql10-odbc.x86_64 12.00.0000-1PGDG.rhel7 @pgdg10 postgresql10-plperl.x86_64 10.11-2PGDG.rhel7 @pgdg10 postgresql10-plpython.x86_64 10.11-2PGDG.rhel7 @pgdg10 postgresql10-pltcl.x86_64 10.11-2PGDG.rhel7 @pgdg10 postgresql10-server.x86_64 10.11-2PGDG.rhel7 @pgdg10 postgresql10-tcl.x86_64 2.4.0-1.rhel7 @pgdg10 postgresql10-tcl-debuginfo.x86_64 2.3.1-1.rhel7 @pgdg10 postgresql10-test.x86_64 10.11-2PGDG.rhel7 @pgdg10 # su - postgres Last login: Wed Jan 15 18:34:12 CST 2020 on pts/0 $ $ $ psql -c "select version();"version ----------------------------------------------------------------------------------------------------------PostgreSQL 10.11 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit (1 row)

oid、tableoid、ctid

oid 為內部行對象標識符,強烈不建議(或者禁止)用戶表使用oid。用戶默認建表時 with oids=false
tableoid 行歸屬的表的oid,通常在有繼承關系的父表時,可以快速判斷行數據所屬的子表。
ctid 標記行的物理位置,格式為 (m,n) 其中 m表示塊號,n表示在塊內的行號

xmin、xmax、cmin、cmax

多版本實現中控制數據行的可見性

插入行時:xmin 置為當前事務ID,xmax 置為 0
刪除行時:xmax 置為當前事務ID
更新行時:舊行上的 xmin 保持不變,舊行上的 xmax 置為當前事務ID
新行上的 xmin 置為當前事務ID,新行上的 xmax 置為 0

cmin、cmax 主要是用于判斷同一個事務內的不同命令導致的行版本變化是否可見。這個理解透徹后再補充下

create table 試一下

# su - postgres $ psqlpostgres=# create table tmp_t0 (id bigint primary key,name varchar(100) );postgres=# select oid,relname from pg_class where relname='tmp_t0';oid | relname --------+---------379767 | tmp_t0 (1 row)postgres=# select attrelid,attname,attnum from pg_attribute where attrelid=379767;attrelid | attname | attnum ----------+----------+--------379767 | tableoid | -7379767 | cmax | -6379767 | xmax | -5379767 | cmin | -4379767 | xmin | -3379767 | ctid | -1379767 | id | 1379767 | name | 2 (8 rows) postgres=# insert into tmp_t0 select 1,'a' ;postgres=# select * from tmp_t0;id | name ----+------1 | a (1 row)postgres=# select tableoid,cmax,xmax,cmin,xmin,ctid,id,name from tmp_t0;tableoid | cmax | xmax | cmin | xmin | ctid | id | name ----------+------+------+------+--------+-------+----+------379767 | 0 | 0 | 0 | 699844 | (0,1) | 1 | a (1 row)

執行 update

postgres=# begin;postgres=# update tmp_t0 set name='b' where id=1;postgres=# select tableoid,cmax,xmax,cmin,xmin,ctid,id,name from tmp_t0;tableoid | cmax | xmax | cmin | xmin | ctid | id | name ----------+------+------+------+--------+-------+----+------379767 | 0 | 0 | 0 | 699845 | (0,2) | 1 | b (1 row)

可以看到新數據的 xmin=699845 ctid=(0,2)

另外一個會話查詢數據

postgres=# select tableoid,cmax,xmax,cmin,xmin,ctid,id,name from tmp_t0;tableoid | cmax | xmax | cmin | xmin | ctid | id | name ----------+------+--------+------+--------+-------+----+------379767 | 0 | 699845 | 0 | 699844 | (0,1) | 1 | a (1 row)

符合預期

參考:

總結

以上是生活随笔為你收集整理的postgresql 数据库表隐藏列 oid、tableoid、ctid、xmin、xmax、cmin、cmax的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。