转自 https://www.2cto.com/database/201206/137301.html
 
Postgresql的隐藏系统
 
和oracle数据库一样,postgresql也有自身的一套隐藏的系统列。下面介绍如下: 
 
1.oid 
 
oid是object identifier的简写,其相关的参数设置default_with_oids设置一般默认是false,或者创建表时指定with (oids=false),其值长度32bit,实际的数据库系统应用中并不能完全保证其唯一性;   www.2cto.com  
 
2.tableoid 
 
是表对象的一个唯一标识符,可以和pg_class中的oid联合起来查看 
 
3.xmin 默认排序(最新的会在最下面)
 
是插入的事务标识符,是用来标识不同事务下的一个版本控制。每一次更新该行都会改变这个值。可以和mvcc版本结合起来看 
 
4.xmax 
 
是删除更新的事务标识符,如果该值不为0,则说明该行数据当前还未提交或回滚。比如设置begin事务时可以明显看到该值的变化 
 
5.cmin 
 
插入事务的命令标识符,从0开始 
 
6.cmax 
 
删除事务的命令标识符,或者为0 
 
7.ctid
 
是每行数据在表中的一个物理位置标识符,和oracle的rowid类似,但有一点不同,当表被vacuum full或该行值被update时该值可能会改变。所以定义表值的唯一性最好还是自己创建一个序列值的主键列来标识比较合适。不过使用该值去查询时速度还是非常快的。 
 
下面举例说明:
 
postgres=# create table test(id int,name varchar);
CREATE TABLE
 
postgres=# insert into test select generate_series(1,3),repeat('kenyon',2);
INSERT 0 3
 
postgres=# select cmin,cmax,xmin,xmax,ctid from test;
 cmin | cmax | xmin | xmax | ctid  
--------+--------+------+--------+-------
    0 |    0 | 1852 |    0 | (0,1)
    0 |    0 | 1852 |    0 | (0,2)
    0 |    0 | 1852 |    0 | (0,3)
(3 rows)
 
我们可以看到xmin值是一样的,表示是同一个事务
 
postgres=# begin;
BEGIN
postgres=# insert into test values (4,'a');
INSERT 0 1
postgres=# insert into test values (5,'aa');
INSERT 0 1
postgres=# insert into test values (6,'aa');
INSERT 0 1
postgres=# insert into test values (7,'aad');
INSERT 0 1
postgres=# commit;
COMMIT
 
postgres=# select cmin,cmax,xmin,xmax,ctid,* from test;
 cmin | cmax | xmin | xmax | ctid | id | name     
--------+--------+------+--------+-------+-----+--------------
    0 |    0 | 1852 |    0 | (0,1) |  1 | kenyonkenyon
    0 |    0 | 1852 |    0 | (0,2) |  2 | kenyonkenyon
    0 |    0 | 1852 |    0 | (0,3) |  3 | kenyonkenyon
    0 |    0 | 1853 |    0 | (0,4) |  4 | a
    1 |    1 | 1853 |    0 | (0,5) |  5 | aa
    2 |    2 | 1853 |    0 | (0,6) |  6 | aa
    3 |    3 | 1853 |    0 | (0,7) |  7 | aad
 
这里我们可以看到cmin和cmax值有了变化
 
postgres=# begin;
BEGIN
postgres=# update test set name = 'keke' where id = 7;
UPDATE 1
postgres=# update test set name = 'kekeke' where id = 6;
UPDATE 1
postgres=# update test set name = 'kenyon_test' where id = 5;
UPDATE 1
 
在另外一个会话中我们去查看xmax值
 
postgres=# select cmin,cmax,xmin,xmax,ctid,* from test;
 cmin | cmax | xmin | xmax | ctid | id |     name     
--------+--------+------+------+-------+-----+--------------
    0 |    0 | 1852 |  0 | (0,1) |  1 | kenyonkenyon
    0 |    0 | 1852 |  0 | (0,2) |  2 | kenyonkenyon
    0 |    0 | 1852 |  0 | (0,3) |  3 | kenyonkenyon
    0 |    0 | 1853 |  0 | (0,4) |  4 | a
    2 |    2 | 1853 | 1854 | (0,5) |  5 | aa
    1 |    1 | 1853 | 1854 | (0,6) |  6 | aa
    0 |    0 | 1853 | 1854 | (0,7) |  7 | aad
(7 rows)
 
原会话中我们执行commit并查看
 
postgres=# commit;
COMMIT
postgres=# select cmin,cmax,xmin,xmax,ctid,* from test;
 cmin | cmax | xmin | xmax |  ctid | id | name     
--------+--------+------+--------+---------+-----+--------------
    0 |    0 | 1852 |    0 | (0,1)  |  1 | kenyonkenyon
    0 |    0 | 1852 |    0 | (0,2)  |  2 | kenyonkenyon
    0 |    0 | 1852 |    0 | (0,3)  |  3 | kenyonkenyon
    0 |    0 | 1853 |    0 | (0,4)  |  4 | a
    0 |    0 | 1854 |    0 | (0,8)  |  7 | keke
    1 |    1 | 1854 |    0 | (0,9)  |  6 | kekeke
    2 |    2 | 1854 |    0 | (0,10) |  5 | kenyon_test
(7 rows)
 
这时我们可以看到ctid也有了变化,在原来的基础上(0,7)往上累积,另外xmax因为事务被commit 的缘故也被置为0了。 再做下delete和insert的一个简单操作
 
postgres=# delete from test where id = 1;
DELETE 1
postgres=# insert into test values (8,'jackson');
INSERT 0 1
postgres=# select cmin,cmax,xmin,xmax,ctid,* from test;
 cmin | cmax | xmin | xmax |  ctid | id | name     
--------+--------+------+--------+---------+-----+--------------
    0 |    0 | 1852 |    0 | (0,2)  |  2 | kenyonkenyon
    0 |    0 | 1852 |    0 | (0,3)  |  3 | kenyonkenyon
    0 |    0 | 1853 |    0 | (0,4)  |  4 | a
    0 |    0 | 1854 |    0 | (0,8)  |  7 | keke
    1 |    1 | 1854 |    0 | (0,9)  |  6 | kekeke
    2 |    2 | 1854 |    0 | (0,10) |  5 | kenyon_test
    0 |    0 | 1856 |    0 | (0,11) |  8 | jackson
 
这时我们可以看到其实delete的事务ID(xmin)值是1855,insert的(xmin)值是1856,ctid往上累计 
 最后看一下tableoid和pg_class中oid的关系,(oid不说了,系统中一般设置为false)
 
postgres=# select tableoid,cmin,cmax,xmin,xmax,ctid,* from test;
 tableoid | cmin | cmax | xmin | xmax |  ctid | id | name     
------------+--------+--------+------+--------+---------+-----+--------------
    24601 |    0 |    0 | 1852 |    0 | (0,2)  |  2 | kenyonkenyon
    24601 |    0 |    0 | 1852 |    0 | (0,3)  |  3 | kenyonkenyon
    24601 |    0 |    0 | 1853 |    0 | (0,4)  |  4 | a
    24601 |    0 |    0 | 1854 |    0 | (0,8)  |  7 | keke
    24601 |    1 |    1 | 1854 |    0 | (0,9)  |  6 | kekeke
    24601 |    2 |    2 | 1854 |    0 | (0,10) |  5 | kenyon_test
    24601 |    0 |    0 | 1856 |    0 | (0,11) |  8 | jackson
(7 rows)
 
postgres=# select oid,relname,relfilenode,relkind from pg_class where oid = 24601;
  oid | relname | relfilenode | relkind 
--------+-----------+-------------+---------
 24601 | test    |     24601 | r
 

Postgresql的隐藏系统列的更多相关文章

  1. Android之弹出/隐藏系统软键盘

    Android弹出/隐藏系统软键盘的代码如下: InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT ...

  2. ios7隐藏系统底部导航

    ios7隐藏系统底部导航 minimal-ui <meta id="viewport" name="viewport" content="wid ...

  3. iOS 隐藏系统的导航,使用自定义的导航

    #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...

  4. 解决JQuery中datatables设置隐藏显示列多次提交后台刷新数据的问题

    此次项目开发过程中用到了Jquery的Datatables插件,无疑他是数据列表展示,解决MVC中同步过程中先走控制器后返回视图,查询数据过程中无法提示等待的弊端, 而且他所提供的各种方法也都有较强的 ...

  5. android如何调用显示和隐藏系统默认的输入法(一)

    1.调用显示系统默认的输入法 方法一. InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_MET ...

  6. 利用 /proc/sys/kernel/core_pattern隐藏系统后门

    ref:https://xz.aliyun.com/t/1098/ 这里所说的core_pattern 指的是:/proc/sys/kernel/core_pattern. 我们知道在Linux系统中 ...

  7. SpringBoot系统列 2 - 配置文件,多环境配置(dev,qa,online)

    实现项目的多环境配置的方法有很多,比如通过在Pom.xml中配置profiles(最常见) 然后在Install项目打War包的时候,根据需求打不同环境的包,如图: 这种配置多环境的方法在SSM框架中 ...

  8. SpringBoot系统列 1 - HelloWorld!

    学习SpringBoot系统列之HelloWorld! 1.新建一个Maven项目 2.添加POM配置 <parent> <groupId>org.springframewor ...

  9. jqgrid 让隐藏的列在编辑状态时出现且可编辑

    有时,我们需要隐藏一个列数据,但在启动编辑时又能够被编辑. 1.设置列为编辑:editable: true 2.设置 editrules属性值为: edithidden: true colModel: ...

随机推荐

  1. socket的阻塞与非阻塞,同步与异步

    同步/异步主要针对C端: 同步:      所谓同步,就是在c端发出一个功能调用时,在没有得到结果之前,该调用就不返回.也就是必须一件一件事做,等前一件做完了才能做下一件事. 例如普通B/S模式(同步 ...

  2. RocketMQ源码 — 五、 主要feature及其实现方式

    RocketMQ的主要特点以及实现方式 单机支持1万以上持久队列 所有数据单独存储到一个CommitLog,完全顺序写,随机读 在一个broker上一个DefaultMessageStore管理一个c ...

  3. JavaScript基础——深入学习async/await

    本文由云+社区发表 本篇文章,小编将和大家一起学习异步编程的未来--async/await,它会打破你对上篇文章Promise的认知,竟然异步代码还能这么写! 但是别太得意,你需要深入理解Promis ...

  4. Qt 编程中 namespace Ui { class Widget; } 解析

    class Widget 里面有个声明 Ui::Widget *ui,这个 ui 是使用 namespace Ui 里的 Widget 类声明的,该类只是简单的继承了 ui_widget.h 里的 U ...

  5. springBoot系列-->springBoot注解大全

    一.注解(annotations)列表 @SpringBootApplication:包含了@ComponentScan.@Configuration和@EnableAutoConfiguration ...

  6. .NET Core 实践一:微服务架构的优点(转)

    微服务现在已经是各种互联网应用首选的云架构组件,无论是 BAT 还是 滴滴.美团 ,微服务都是重要的一环. 相对于微服务,传统应用架构有以下缺点: 1. 业务代码混杂,团队成员职责边界不清,团队协作体 ...

  7. java连接MySQL数据库的方式

    Java连接数据库的几种方法 *说明 1.以MySQL数据库为例 2.分为四个步骤: 建立数据库连接, 向数据库中提交sql 处理数据库返回的结果 关闭数据库连接 一:JDBC 1.建立数据库连接 只 ...

  8. MySQL技巧(一)

    NOT IN 与 IN 假设我们又一张score表如下 我们需要查询所有不是性别代号为"0"的学生数据 ); 很明显,not in 就是排除的意思. exists 与 not ex ...

  9. constructor C++ example

    The constructor for this class could be defined, as usual, as:   Rectangle::Rectangle (int x, int y) ...

  10. GitHub for Windows离线安装包

    国内安装github客户端,真的很痛!! 偶然找到了离线安装包,感谢作者的资源分享!!! 地址:http://download.csdn.net/download/lyg468088/8723039? ...