关于postgresql内部的信息

PostgreSQL 数据类型介绍(五)OID的理解

那oid在哪儿?到底为什么会出现这种情况 ?

龙井网站建设公司成都创新互联公司,龙井网站设计制作,有大型网站制作公司丰富经验。已为龙井千余家提供企业网站建设服务。企业网站搭建\外贸营销网站建设要多少钱,请找那个售后服务好的龙井做网站的公司定做!

来看看postgres官网对 oid的介绍:

根据stackoverflow的高票用户的回答:

*OIDs basically give you a built-in, globally unique id for every row, contained in a system column (as opposed to a user-space column). That's handy for tables where you don't have a primary key, have duplicate rows, etc. For example, if you have a table with two identical rows, and you want to delete the oldest of the two, you could do that using the oid column.

In my experience, the feature is generally unused in most postgres-backed applications (probably in part because they're non-standard), and their use is essentially deprecated :

In PostgreSQL 8.1 default_with_oids is off by default; in prior versions of PostgreSQL, it was on by default.

The use of OIDs in user tables is considered deprecated, so most installations should leave this variable disabled. Applications that require OIDs for a particular table should specify WITH OIDS when creating the table. This variable can be enabled for compatibility with old applications that do not follow this behavior.

大意是你要是有个表没有用主键,这时候可以把oid充当为主键使用,当然这是没办法的办法。

总结: oid是给内部表做标识用的,不推荐使用。 建议将 default_with_oids 设置为off。 建表的时候,如果想使用主键,请自行建立。oid本身大小固定的,万一 行数超过了oid 的最大限制数(4 byte int),那就无法插入新行了。

PostgreSQL 有哪些经典入门书籍

PostgreSQL(数据库)资料

About:PostgreSQL About

《PostgreSQL 源码分析系列》

PostgreSQL 源码分析系列

介绍:PostgreSQL 源码分析系列文章

《PG 内存上下文》

介绍:PG 内存上下文,code

《PostgreSQL及其代码的结构》

介绍:PostgreSQL及其代码的结构

《A Tour of PostgreSQL Internals》

介绍:PostgreSQL内部的概览,可以结合上面的pg代码结构来阅读

《PostgreSQL 中的 Json —从使用到源码》

介绍:PostgreSQL 中的 Json —从使用到源码

《PostgreSQL锁机制分析》

AntDB/PostgreSQL内部原理:表Page结构解析

PostgreSQL 中 Page 是一个磁盘 Block 上的一个抽象结构,用于描述 Block 内部的数据结构与组织形式。

所有数据块在读写时,必须按 Page 格式进行访问操作。

PostgreSQL 11 的 Page 格式(包含 3 行数据)如下:

行指针之前的 Page Header 总空间消耗为: (64 + 16 * 6 + 32) bit / 8 = 24 Byte

以下分别对这些结构以及对应的标志位的值进行说明:

Tuple 类型和行中各列数据的头部信息共享相同的数据结构,所以可以用相同的方法来构建和检查。但需求略有不同,数据不需要事务可见性信息,它需要一个长度字段和一些嵌入式类型信息。我们可以通过覆盖 Heap Tuple 上的 xmin/cmin/xmax/cmax/xvac 字段来实现数据上的需求。

Heap tuple 的头部信息,为了避免空间浪费,应该将字段以一种避免结构扩充的方式来布局。

通常,内存中所有的 tuples 都会使用数据字段进行初始化,当一个 tuple 需要写入表中时,事务相关的字段将会被写入,并覆盖数据字段。

Heap tuple 的整体结构包括:

通过 pageinspect 扩展模块,可以在低层次观察 page 中的实际数据,而不用考虑事务及相关可见性限制,这通常用于 DEBUG 目的的数据研究。

其常用函数说明如下:

创建模块

创建测试表

查看 Page Header

数据含义解析:

查看 Page 中的记录(Tuple)

数据含义解析:

解析 Tuple 数据

尝试多次更新同一条一条数据

再次查看页面数据

数据含义解析:

删除一条数据

再次查看页面数据

数据含义解析:

通过跟踪 t_xmin, t_xmax, t_ctid 三个字段的变化,可以得到 Tuple 数据的多版本变化历史,这也是 PostgreSQL 的 MVCC 实现原理

PostgreSQL 的多版本(MVCC)与 Oracle 有很大的不同,在于其将多版本信息与表数据存储在一起,这种多版本实现方式有其优势与局限性。

优势

劣势


网站栏目:关于postgresql内部的信息
链接URL:http://lszwz.com/article/dsdgjos.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款