- 每个表和索引 都是单独的文件, 当表或索引太大时 会扩展到多个文件
- 每套库都有自己的数据字典表 pg_class等,pg_class的文件号是1529
- pg_global表空间里记录了核心字典信息 就是有哪些数据库 和 数据库的oid
- postgreSQL的块头是 pageHeader ,pageheader 24个字节 之后是 ItemIdData 即行指针, 之后是free space,之后是数据tuple heap
- pageheader里没有该page的位置信息, 但这个文档 https://www.jianshu.com/p/375e2b9fd079 里说有pd_type和 pd_oid 信息, 即24个字节里的 最后4个字节,但源代码里看没有这些结构,源代码里最后4字节是 TransactionId(uint32) pd_prune_xid; https://doxygen.postgresql.org/bufpage_8h_source.html 。这些结构可能是某些特殊发行版本里搞出来的。
- 另外在tuple的ctid里有块号和行号,但是没有文件号,即如(0,0),(0,1),(0,3)这样的序列信息没有意义
Overall Page Layout
| Item | Description |
|---|---|
| PageHeaderData | 20 bytes long. Contains general information about the page, including free space pointers. |
| ItemIdData | Array of (offset,length) pairs pointing to the actual items. 4 bytes per item. |
| Free space | The unallocated space. New item pointers are allocated from the start of this area, new items from the end. |
| Items | The actual items themselves. |
| Special space | Index access method specific data. Different methods store different data. Empty in ordinary tables. |
PageHeaderData Layout
| Field | Type | Length | Description |
|---|---|---|---|
| pd_lsn | XLogRecPtr | 8 bytes | LSN: next byte after last byte of xlog record for last change to this page |
| pd_tli | TimeLineID | 4 bytes | TLI of last change |
| pd_lower | LocationIndex | 2 bytes | Offset to start of free space |
| pd_upper | LocationIndex | 2 bytes | Offset to end of free space |
| pd_special | LocationIndex | 2 bytes | Offset to start of special space |
| pd_pagesize_version | uint16 | 2 bytes | Page size and layout version number information |
HeapTupleHeaderData Layout
| Field | Type | Length | Description |
|---|---|---|---|
| t_xmin | TransactionId | 4 bytes | insert XID stamp |
| t_cmin | CommandId | 4 bytes | insert CID stamp |
| t_xmax | TransactionId | 4 bytes | delete XID stamp |
| t_cmax | CommandId | 4 bytes | delete CID stamp (overlays with t_xvac) |
| t_xvac | TransactionId | 4 bytes | XID for VACUUM operation moving a row version |
| t_ctid | ItemPointerData | 6 bytes | current TID of this or newer row version |
| t_natts | int16 | 2 bytes | number of attributes |
| t_infomask | uint16 | 2 bytes | various flag bits |
| t_hoff | uint8 | 1 byte | offset to user data |