广告
返回顶部
首页 > 资讯 > 数据库 >PostgreSQL系统列 System Columns
  • 577
分享到

PostgreSQL系统列 System Columns

2024-04-02 19:04:59 577人浏览 薄情痞子
摘要

每个表都有隐藏的系统列,创建表列的时候不能和系统列名相同,下面讲解一下postgresql有哪些系统列.(1)oid(4 bytes)object identifier(即object ID)主要用于系统表

每个表都有隐藏的系统列,创建表列的时候不能和系统列名相同,下面讲解一下postgresql有哪些系统列.


(1)oid(4 bytes)

object identifier(即object ID)主要用于系统表如pg_class(记录table的一个表),pg_namespace(记录schema的一个表),

创建表时,如果指定with oids,则存在oid列。还可以由参数default_with_oids控制,默认是off,表示不加with oids建表时,没有oid列。


eg:


#查看pg_class这个条记录对应的oid

postgres=# select oid,relname from pg_class where oid='pg_class'::reGClass;

oid  | relname  

------+----------

1259 | pg_class


#创建一个新的表


postgres=# create table t1(c1 integer,c2 varchar(20)) with oids;

CREATE TABLE


postgres=# insert into t1 select 1,'aaa';

INSERT 16456 1


postgres=# insert into t1 values(2,'bbb');

INSERT 16457 1


postgres=# \d+ t1;

                                 Table "public.t1"

Column |         Type          | Modifiers | Storage  | Stats target | Description

--------+-----------------------+-----------+----------+--------------+-------------

c1     | integer               |           | plain    |              |

c2     | character varying(20) |           | extended |              |

Has OIDs: yes


postgres=# select oid,c1,c2 from t1;

  oid  | c1 | c2  

-------+----+-----

16456 |  1 | aaa

16457 |  2 | bbb


(2)tableid(4 bytes)

表对象的一个唯一标识符,一个表只对应一个tableoid,可以将tableoid与pgclass的oid列连接起来,以获得表名


postgres=# select oid,tableoid from t1;

  oid  | tableoid

-------+----------

16456 |    16453

16457 |    16453

16458 |    16453


postgres=# select tableoid from t2;

tableoid

----------

    16464


postgres=# select oid,relname from pg_class ;

  oid  |                 relname                 

-------+-----------------------------------------

16453 | t1

16464 | t2


postgres=# select relname from pg_class where oid in (16453,16464);

relname

---------

t1

t2


(3)ctid(6 bytes)

在表中的一个物理位置标识符,和oracle的rowid类似,但有一点不同,当表被vacuum full或该行值被update时该值可能会改变。所以定义表值的唯一性最好还是自己创建一个序列值的主键列来标识比较合适


(4)xmin

是插入的事务标识符transaction ID,是用来标识不同事务下的一个版本控制。每一次更新该行都会改变这个值。可以和mvcc版本结合起来看


(5)xmax

是删除更新的事务标识符transaction ID,如果该值不为0,则说明该行数据当前还未提交或回滚。比如设置begin...commit事务时可以明显看到该值的变化


(6)cmin

插入事务的命令标识符command identifier,从0开始


(7)cmax

删除事务的命令标识符command identifier,或者为0


eg:

postgres=# create table t1(c1 integer,c2 varchar(20));

postgres=# insert into t1 select generate_series(1,3),repeat('hello',2);


#三行记录的xmin一样,表示是同一个事物

postgres=# select cmin,cmax,xmin,xmax,ctid,* from t1;

cmin | cmax | xmin | xmax | ctid  | c1 |     c2     

------+------+------+------+-------+----+------------

    0 |    0 | 1806 |    0 | (0,1) |  1 | hellohello

    0 |    0 | 1806 |    0 | (0,2) |  2 | hellohello

    0 |    0 | 1806 |    0 | (0,3) |  3 | hellohello


begin;

insert into t1 values(4,'aaa');

insert into t1 values(5,'bbb');

insert into t1 values(6,'ccc');

commit;


#第四行,第五行,第六行的xmin不同,表示是不同的事物,cmin和cmax也都发生变化了

postgres=# select cmin,cmax,xmin,xmax,ctid,* from t1;

cmin | cmax | xmin | xmax | ctid  | c1 |     c2     

------+------+------+------+-------+----+------------

    0 |    0 | 1806 |    0 | (0,1) |  1 | hellohello

    0 |    0 | 1806 |    0 | (0,2) |  2 | hellohello

    0 |    0 | 1806 |    0 | (0,3) |  3 | hellohello

    0 |    0 | 1807 |    0 | (0,4) |  4 | aaa

    1 |    1 | 1807 |    0 | (0,5) |  5 | bbb

    2 |    2 | 1807 |    0 | (0,6) |  6 | ccc


session1:

postgres=# begin;

postgres=# update t1 set c2='cdhu' where c1=5;

postgres=# update t1 set c2='cdhucdhu' where c1=6;


#此时的ctid变化了:

postgres=# select cmin,cmax,xmin,xmax,ctid,* from t1;

cmin | cmax | xmin | xmax | ctid  | c1 |     c2     

------+------+------+------+-------+----+------------

    0 |    0 | 1806 |    0 | (0,1) |  1 | hellohello

    0 |    0 | 1806 |    0 | (0,2) |  2 | hellohello

    0 |    0 | 1806 |    0 | (0,3) |  3 | hellohello

    0 |    0 | 1807 |    0 | (0,4) |  4 | aaa

    0 |    0 | 1808 |    0 | (0,7) |  5 | cdhu

    1 |    1 | 1808 |    0 | (0,8) |  6 | cdhucdhu

(6 rows)


再开一个会话


session2:

#上面update事物还没有结束,所以xmax现在不为0:

postgres=# select cmin,cmax,xmin,xmax,ctid,* from t1;

cmin | cmax | xmin | xmax | ctid  | c1 |     c2     

------+------+------+------+-------+----+------------

    0 |    0 | 1806 |    0 | (0,1) |  1 | hellohello

    0 |    0 | 1806 |    0 | (0,2) |  2 | hellohello

    0 |    0 | 1806 |    0 | (0,3) |  3 | hellohello

    0 |    0 | 1807 |    0 | (0,4) |  4 | aaa

    0 |    0 | 1807 | 1808 | (0,5) |  5 | bbb

    1 |    1 | 1807 | 1808 | (0,6) |  6 | ccc


session1:

postgres=# commit;


session2:

postgres=# select cmin,cmax,xmin,xmax,ctid,* from t1;

cmin | cmax | xmin | xmax | ctid  | c1 |     c2     

------+------+------+------+-------+----+------------

    0 |    0 | 1806 |    0 | (0,1) |  1 | hellohello

    0 |    0 | 1806 |    0 | (0,2) |  2 | hellohello

    0 |    0 | 1806 |    0 | (0,3) |  3 | hellohello

    0 |    0 | 1807 |    0 | (0,4) |  4 | aaa

    0 |    0 | 1808 |    0 | (0,7) |  5 | cdhu

    1 |    1 | 1808 |    0 | (0,8) |  6 | cdhucdhu


您可能感兴趣的文档:

--结束END--

本文标题: PostgreSQL系统列 System Columns

本文链接: https://www.lsjlt.com/news/34629.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • PostgreSQL系统列 System Columns
    每个表都有隐藏的系统列,创建表列的时候不能和系统列名相同,下面讲解一下PostgreSQL有哪些系统列.(1)oid(4 bytes)object identifier(即object ID)主要用于系统表...
    99+
    2022-10-18
  • PostgreSQL 10.12 安装系列 - 源码安装
    三、     源码安装 3.1. 下载地址: https://www.postgresql.org/ftp/source/       &n...
    99+
    2022-10-18
  • postgresql踩坑系列之关于to_date()问题
    目录postgresql关于to_date()问题postgresql中to_date()函数使用问题解决方式总结postgresql关于to_date()问题 这里是对postgr...
    99+
    2023-03-21
    postgresql踩坑 关于to_date() postgresql to_date()
  • 《JeecgBoot系列》 多数据源配置(PostgreSQL为例)
    JeecgBoot系列 多数据源配置 一、jeecg-boot-module-system模块 jeecg-boot-module-system模块下,这里先看application这几个环境配置文件 application.yml用于决定...
    99+
    2023-08-17
    mysql 数据库 postgresql
  • Linux系统怎么安装postgresql
    这篇文章主要介绍了Linux系统怎么安装postgresql的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Linux系统怎么安装postgresql文章都会有所收获,下面我们一起来看看吧。PostgreSQL是...
    99+
    2023-06-28
  • Linux系统如何安装PostgreSQL
    这篇文章给大家分享的是有关Linux系统如何安装PostgreSQL的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。PostgreSQL 简介:PostgreSQL是一个功能强大的开源对象关系型数据库系统,他使用和...
    99+
    2023-06-28
  • 怎样解析Linux系统/etc/pam.d/system-auth文件
    这篇文章的内容主要围绕怎样解析Linux系统/etc/pam.d/system-auth文件进行讲述,文章内容清晰易懂,条理清晰,非常适合新手学习,值得大家去阅读。感兴趣的朋友可以跟随小编一起阅读吧。希望大家通过这篇文章有所收获!在Linu...
    99+
    2023-06-28
  • Win10系统BAD SYSTEM CONFIG INFO蓝屏怎么解决
    今天小编给大家分享一下Win10系统BAD SYSTEM CONFIG INFO蓝屏怎么解决的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起...
    99+
    2023-07-01
  • TinkerTool System 6 for Mac(系统维护设置工具)
    TinkerTool System 6是一系列系统实用程序功能,可帮助您在Apple Macintosh计算机上执行高级管理任务。该应用程序使用自适应用户界面,该界面可自动调整计算机型号和您正在运行的macOS版本。当前情况下可用的所有选项...
    99+
    2023-06-05
  • PostgreSQL -- 系统参数类型与设置
    一、PostgreSQL参数类型 PostgreSQL 系统所有的系统参数配置项对大小都不敏感,主要有Bool、Int、浮点数、字符串、枚举值 参数的修改,有些需要重启数据库、有些普通用户直接修改、有些需要...
    99+
    2022-10-18
  • 如何在linux系统下安装PostgreSQL
    这篇文章跟大家分析一下“如何在linux系统下安装PostgreSQL”。内容详细易懂,对“如何在linux系统下安装PostgreSQL”感兴趣的朋友可以跟着小编的思路慢慢深入来阅读一下,希望阅读后能够对大家有所帮助。下面跟着小编一起深入...
    99+
    2023-06-28
  • Windows系统下获取SYSTEM权限设置的方法
    默认情况下,我们无法直接在登录对话框上以SYSTEM帐户的身份登录到Windows桌面环境。实际上SYSTEM帐户早就已经“盘踞”在系统中了。想想也是,连负责用户验证的Winlogon、Lsass...
    99+
    2023-06-03
    Windows 获取SYSTEM权限 方法 权限 系统 SYSTEM
  • 电脑影子系统bad system config info怎么解决
    本文小编为大家详细介绍“电脑影子系统bad system config info怎么解决”,内容详细,步骤清晰,细节处理妥当,希望这篇“电脑影子系统bad system config info怎么解决”文章能帮助大家解决疑惑,下面跟着小编的...
    99+
    2023-07-01
  • 在Linux系统上安装PostgreSQL数据库
    目录一、准备工作二、安装PostgreSQL2.1、选择版本2.2、安装yum源2.3、安装PostgreSQL三、设置PostgreSQL3.1、初始化数据库3.2、设置数据库自启...
    99+
    2022-11-13
  • PostgreSQL一条SQL引发系统out of memory
    错误描述(1) Postgres执行的原SQL:select COALESCE(m1.place_id, m2.place_id, m3.place_id) ...
    99+
    2022-10-18
  • PostgreSQL免费公开课第15期-调优系列课程(pgBagder)
    十五、Postgresql 调优系列公开课二(pgBagder介绍) PostgreSQL新一代日志分析器pgBagder简介 pgBagder部署 如何产生类似于AWR报告,基于一小时、一天、一周、一月的报告 如何分析pgBade...
    99+
    2021-01-16
    PostgreSQL免费公开课第15期-调优系列课程(pgBagder)
  • PostgreSQL 源码解读(82)- 查询语句#67(PortalXXX系列函数)
    本节介绍了PortalXXX函数,这些函数在create_simple_query中被调用,包括CreatePortal、PortalDefineQuery、PortalSetRe...
    99+
    2022-10-18
  • Linux系统:Centos7下搭建PostgreSQL关系型数据库
    本文源码:GitHub·点这里 || GitEE·点这里一、PostgreSQL简介1、数据库简介PostgreSQL是一个功能强大的开源数据库系统,具有可靠性、稳定性、数据一致性等特点,且可以运行在所有主流操作系统上,包括Linux、U...
    99+
    2023-06-05
  • C语言怎么利用system调用系统命令行
    本篇内容介绍了“C语言怎么利用system调用系统命令行”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!system,顾名思义,就是调用系统命...
    99+
    2023-06-22
  • C语言利用system调用系统命令行详情
    system,顾名思义,就是调用系统命令行,输入为字符串,然后把这个字符串输出给命令行,让命令行执行。 为了测试其特性,可以做一个小程序: //system.c #include&l...
    99+
    2022-11-12
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作