PostgreSQL数据库表的内部结构

A page within a table contains three kinds of data described as follows:

  1. heap tuple(s) – A heap tuple is a record data itself. They are stacked in order from the bottom of the page. The internal structure of tuple is described in Section 5.2 and Chapter 9 as the knowledge of both Concurrency Control(CC) and WAL in PostgreSQL are required.
  2. line pointer(s) – A line pointer is 4 byte long and holds a pointer to each heap tuple. It is also called an item pointer.
  3. Line pointers form a simple array, which plays the role of index to the tuples. Each index is numbered sequentially from 1, and called offset number. When a new tuple is added to the page, a new line pointer is also pushed onto the array to point to the new one.
  4. header data – A header data defined by the structure PageHeaderData is allocated in the beginning of the page. It is 24 byte long and contains general information about the page. The major variables of the structure are described below.
    • pd_lsn – This variable stores the LSN of XLOG record written by the last change of this page. It is an 8-byte unsigned integer, related to the WAL (Write-Ahead Logging) mechanism. The details are described in Chapter 9.
    • pd_checksum – This variable stores the checksum value of this page. (Note that this variable is supported in version 9.3 or later; in earlier versions, this part had stored the timelineId of the page.)
    • pd_lower, pd_upper – pd_lower points to the end of line pointers, and pd_upper to the beginning of the newest heap tuple.
    • pd_special – This variable is for indexes. In the page within tables, it points to the end of the page. (In the page within indexes, it points to the beginning of special space which is the data area held only by indexes and contains the particular data according to the kind of index types such as B-tree, GiST, GiN, etc.)

An empty space between the end of line pointers and the beginning of the newest tuple is referred to as free space or hole.

To identify a tuple within the table, tuple identifier (TID) is internally used. A TID comprises a pair of values: the block number of the page that contains the tuple, and the offset number of the line pointer that points to the tuple. A typical example of its usage is index. See more detail in Section 1.4.2.

While the HeapTupleHeaderData structure contains seven fields, four fields are required in the subsequent sections.

  • t_xmin holds the txid of the transaction that inserted this tuple.
  • t_xmax holds the txid of the transaction that deleted or updated this tuple. If this tuple has not been deleted or updated, t_xmax is set to 0, which means INVALID.
  • t_cid holds the command id (cid), which means how many SQL commands were executed before this command was executed within the current transaction beginning from 0. For example, assume that we execute three INSERT commands within a single transaction: ‘BEGIN; INSERT; INSERT; INSERT; COMMIT;‘. If the first command inserts this tuple, t_cid is set to 0. If the second command inserts this, t_cid is set to 1, and so on.
  • t_ctid holds the tuple identifier (tid) that points to itself or a new tuple. tid, described in Section 1.3, is used to identify a tuple within a table. When this tuple is updated, the t_ctid of this tuple points to the new tuple; otherwise, the t_ctid points to itself.

引用:http://www.interdb.jp/pg/pgsql01.html

原文地址:https://www.cnblogs.com/kuang17/p/10936433.html

时间: 2024-08-30 14:29:43

PostgreSQL数据库表的内部结构的相关文章

数据库并发事务控制四:postgresql数据库的锁机制二:表锁

在博文<数据库并发事务控制四:postgresql数据库的锁机制 > http://blog.csdn.net/beiigang/article/details/43302947 中后面提到: 常规锁机制可以参考pg的官方手册,章节和内容见下面 13.3. Explicit Locking http://www.postgresql.org/docs/9.4/static/explicit-locking.html 这节分为:表锁.行锁.页锁.死锁.Advisory锁(这个名字怎么翻译好???

PostgreSQL数据库中获取表主键名称

PostgreSQL数据库中获取表主键名称 一.如下表示,要获取teacher表的主键信息: select pg_constraint.conname as pk_name,pg_attribute.attname as colname,pg_type.typname as typename from pg_constraint inner join pg_class on pg_constraint.conrelid = pg_class.oid inner join pg_attribute

PowerDesigner反向工程PostgreSQL数据库

1. 环境准备: a)         安装PowerDesigner,以PowerDesigner15.1为例 b)         安装java jdk,以jdk-7-windows-i586为例 c)         下载postgressql jdbc驱动jar包,以postgresql-8.1-415.jdbc2.jar为例 2. 远程连接PostgreSQL数据库 a)         打开PowerDesigner b)         新建一个空白物理数据模型 点击PowerDe

PostgreSQL数据库内核分析 笔记(这本书没有怎么很好的看,主要就是一些数据结构、概念和流程的文字介绍)

PostgreSQL数据库内核分析 跳转至: 导航. 搜索 目录 1系统概述 2体系结构 3存储管理 4索引 5查询编译 6查询执行 7事务处理与并发控制 8数据库安全 9附录A 用Eclipse开发和调试 系统概述 初始化数据库:./initdb --no-locale -D ../data ./pg_ctl start -D ../data 数据库命令:initdb createuser dropuser createdb dropdb pg_dump pg_restore pg_ctl v

对于多个数据库表对应一个Model问题的思考

最近做项目遇到一个场景,就是客户要求为其下属的每一个分支机构建一个表存储相关数据,而这些表的结构都是一样的,只是分属于不同的机构.这个问题抽象一下就是多个数据库表对应一个Model(或者叫实体类).有了这个问题,我就开始思考在现有的代码中解决问题,最早数据采集部分是用EF来做数据存储的,我查了一下,资料并不多,问了一下对EF比较熟悉的朋友,得出的结论是EF实现这个功能比较复杂,不易实现.EF不能实现就要去找其他的框架,在PDF.NET的讨论群跟大家讨论这个问题的时候,@深蓝医生说PDF.NET可

PostgreSQL介绍以及如何开发框架中使用PostgreSQL数据库

最近准备下PostgreSQL数据库开发的相关知识,本文把总结的PPT内容通过博客记录分享,本随笔的主要内容是介绍PostgreSQL数据库的基础信息,以及如何在我们的开发框架中使用PostgreSQL数据库,希望大家多多提意见. 1.PostgreSQL数据库介绍 PostgreSQL是以加州大学伯克利分校计算机系开发的 POSTGRES,现在已经更名为PostgreSQL.它具有很多不错的特点: 开源:PostgreSQL 是一个自由的对象-关系数据库服务器(数据库管理系统),它在灵活的 B

Django与PostgreSQL数据库的那些事

删除psql数据库:(以数据库Django名为例:) dropdb Django; 新建数据库并属于django: createdb Django -O django 当我们在Django中用了python manage.py syncdb后,会在PostgreSQL中新建了对应的应用的表,但是有时候会发现在admin管理平台时添加数据时出现CSRF错误.这时候,我们要采用以下操作: python manage.py sqlsequencereset T1K   (以T1K应用为例) 然后会出现

Postgresql数据库autovacuum进程启动失败

最近线上Postgresql数据库中其中几台服务器更新时变得非常慢,经过排查和对比,发现时因为autovacuum未启动导致的. 1.使用表pg_stat_all_tables查看autovacuum执行记录 select schemaname,relname,last_autovacuum,last_autoanalyze from pg_stat_all_tables; 如上图,发现所有的对象对应的analyze及vacuum执行记录均为空. 2.使用ps -ef | grep postgr

postgresql数据库的数据导出

一.pg_dump的用法:数据库的导入导出是最常用的功能之一,每种数据库都提供有这方面的工具,例如Oracle的exp/imp,Informix的dbexp/dbimp,MySQL的mysqldump,而PostgreSQL提供的对应工具为pg_dump和pg_restore.pg_dump是用于备份PostgreSQL数据库的工具.它可以在数据库正在使用的时候进行完整一致的备份,并不阻塞其它用户对数据库的访问.转储格式可以是一个脚本或者归档文件.转储脚本的格式是纯文本,包含许多SQL命令,这些