postgresql system columns
来源:互联网 发布:学生 阿里云 编辑:程序博客网 时间:2024/06/03 20:03
每张表都有这么一些隐含列,我们需要了解一下,但是不需要去深究,知道他们含义,以及如何使用即可。
oid:object ID的缩写,32bit,建表时候用with oids,或者是配置default_with_oids参数,这个值并不是唯一,除非自己采取别的措施保证唯一
举例: create table t1 (a int) with (oid=true);
insert into t1 values(1);
select oid, * from t1;
oid | a
-------+---
16469 | 1
tableoid:表对象表示符。该列对于从继承层次中进行查询非常有用,如果没有它,就很难说清行记录来自那个表。tableoid列与数据字典pg_class的oid进行关联可以获取表名。
举例:postgres=# select tableoid from t1;
tableoid
----------
16466
postgres=# select relname,relnamespace from pg_class where oid=16466;
relname | relnamespace
---------+--------------
t1 | 2200
xmin:行插入事务标识,行的插入会更新此xmin
举例:
postgres=# begin;
BEGIN
postgres=# select txid_current();
txid_current
--------------
1722
(1 row)
postgres=# insert into t(i) values(5);
INSERT 0 1
postgres=# select *,xmin,xmax from t where i=5 limit 10;
s | i | xmin | xmax
----------+---+------+------
7 | 5 | 1713 | 0
10000004 | 5 | 1719 | 0
10000005 | 5 | 1721 | 0
10000006 | 5 | 1722 | 0
(4 rows)
postgres=# end;
COMMIT
cmin:插入时的命令标识,从0开始
xmax:删除事务标识,对数据做删除和更新都会更改,该值为非0值时表示删除事务还没有提交,或者试图进行回滚,也就是说这里改值可能有三种状态。
举例:未提交(insert and update)
postgres=# select *,xmin,xmax from t where i=5 limit 10;
s | i | xmin | xmax
----------+---+------+------
7 | 5 | 1713 | 0
10000004 | 5 | 1719 | 0
10000005 | 5 | 1721 | 0
10000006 | 5 | 1722 | 0
(4 rows)
postgres=# begin;
BEGIN
postgres=# select txid_current();
txid_current
--------------
1723
(1 row)
postgres=# delete from t where s=7;
DELETE 1
未提交开启另一session:
postgres=# select *,xmin,xmax from t where i=5 limit 10;
s | i | xmin | xmax
----------+---+------+------
7 | 5 | 1713 | 1723
10000004 | 5 | 1719 | 0
10000005 | 5 | 1721 | 0
10000006 | 5 | 1722 | 0
delete rollback事务:
postgres=# select *,xmin,xmax from t where i=5 limit 10;
s | i | xmin | xmax
----------+---+------+------
10000004 | 5 | 1719 | 0
10000005 | 5 | 1721 | 0
10000006 | 5 | 1722 | 0
(3 rows)
postgres=# begin;
BEGIN
postgres=# select txid_current();
txid_current
--------------
1724
(1 row)
postgres=# delete from t where s=10000004;
DELETE 1
postgres=# rollback;
ROLLBACK
postgres=# select *,xmin,xmax from t where i=5 limit 10;
s | i | xmin | xmax
----------+---+------+------
10000004 | 5 | 1719 | 1724
10000005 | 5 | 1721 | 0
10000006 | 5 | 1722 | 0
(3 rows)
update rollback事务:
postgres=# select *,xmin,xmax from t where i=5 limit 10;
s | i | xmin | xmax
----------+---+------+------
10000004 | 5 | 1719 | 1724
10000005 | 5 | 1721 | 0
10000006 | 5 | 1722 | 0
(3 rows)
postgres=# begin;
BEGIN
postgres=# select txid_current();
txid_current
--------------
1725
(1 row)
postgres=# update t set i=10 where s=10000004;
UPDATE 1
postgres=# rollback;
ROLLBACK
postgres=# select *,xmin,xmax from t where s=10000004 limit 10;
s | i | xmin | xmax
----------+---+------+------
10000004 | 5 | 1719 | 1725
update 提交事务:
postgres=# select *,xmin,xmax from t where s=10000004 limit 10;
s | i | xmin | xmax
----------+---+------+------
10000004 | 5 | 1719 | 1725
(1 row)
postgres=# begin;
BEGIN
postgres=# select txid_current();
txid_current
--------------
1726
(1 row)
postgres=# update t set i=20 where s=10000004;
UPDATE 1
postgres=# commit;
COMMIT
postgres=# select *,xmin,xmax from t where s=10000004 limit 10;
s | i | xmin | xmax
----------+----+------+------
10000004 | 20 | 1726 | 0
总结一下,也就是说不管回滚还是未提交,都会获取新的事务号,但是在update提交的情况下,xmax归零,xmin获取当前事务号。
cmax:删除事务内部的命令标识
txid:有了以上的例子,很好理解了,就是事务ID,这个可不是表的隐含列哦
ctid:另外一篇文章和oracle的 rowid有比较,可以去看
- PostgreSQL System Columns
- postgresql system columns
- System.columns, System.objects, System.tables
- PostgreSQL special sql 1 - list all the columns and primary key
- PowerDesigner 反向 PostgreSQL 时 Unable to list the columns. SQLSTATE =22003 的解决方法
- postgresql 创建一个新的database system
- POJ_1617_Crypto Columns
- Crypto Columns
- Removing Columns
- Removing Columns
- jqgrid columns
- Removing Columns
- Removing Columns
- Dynamic Columns
- columns属性
- PostgreSQL 8.4中系统目录信息 System Catalogs
- Use PostgreSQL collect and analyze Operation System statistics
- postgresql主备之the database system is starting up
- android使用命令行生成数字签名和apk
- SVN报错
- 一起学mini2440裸机开发(一)--第一个led灯点亮
- 数据库优化及找出最消耗资源的查询
- 那些年我们一起对篮球的记忆,文字控吧
- postgresql system columns
- ImageMagick php imagic 扩展安装
- sql with as 用法
- anroid 利用方向传感器或者加速度传感器实现手机或者平板6个方向操作
- Closed-form Solution
- oracle 备份恢复概要介绍
- c#链接Oracle
- http 之session和cookie
- oracle flashback database