在pg数据库中,数据被存储在数据文件里,数据文件内部被划分为固定长度的页(也叫做块)。可在编译数据库时通过–with-blocksize参数指定页的大小,页的默认大小为8k。每个表和索引都以固定尺寸的页数组存储。 在表中,所有页在逻辑上都相同,所以一个特定的行可以被存储在任何页里。 在索引里,第一个页通常保留为元页来保存控制信息, 并且依索引访问方法的不同,在索引里可能有不同类型的页。
本文主要介绍如何查看普通表的页内容。
表页的结构
表页的结构图
表页内容
可以分为5个区域:
pageheaderdata:pgae头信息;占用空间大小为24bytes,用于记录page页的相关信息。后面会详细介绍page头相关信息。
itemiddata:行指针;每个指针占用空间大小为4bytes,用于指向一行数据的存放位置。它由三部分组成:
- lp_off:行数据相对于 page 开始位置的偏移量;它只有15位,这就决定了pg数据库的块大小最大只能设置为32k。
- lp_flags:行指针的状态标志;共有4种状态:
- 0——lp_unused:未使用状态,对应的 lp_len 总是为 0
- 1——normal:已使用状态,指向正常状态的行,对应的 lp_len 总是大于 0
- 2——lp_redirect:被hot特性使用的重定向指针,对应的 lp_len 总是为 0
- 3——lp_dead:死亡状态,一般指指针指向的行已被更新或删除,等待vacuum清理
- lp_len:items部分的实际长度
free space:空闲空间;page中的可用空间。新行的指针从这个区域的开头开始分配,新行的数据从这个区域的结尾开始分配。
items:行数据;后面会介绍items中记录的详细信息。
special space:索引访问模式相关的数据。不同的索引访问方式存放不同的数据。在普通表中为空。
pageheaderdata
pageheaderdata中共包含8个标识:
pd_lsn:记录了最后更改page内容的wal 日志的 lsn号。xlogid:lsn的高32bit,xrecoff:lsn的低32bit。
pd_checksum:页面校验和,为0表示数据库未开启数据页校验和。
pd_flags:标志位,标识当前页面的存储情况。共32个标志位,目前只使用了3个:
- 0x0001——pd_has_free_lines:存在未使用的行指针。
- 0x0002——pd_page_full:页已写满。
- 0x0004——pd_all_visible:页内所有行数据是够对所有事务可见。
- 这三个标志位可叠加记录:比如pd_flags值为0x0005,表示页内存在未使用的行指针,并且页内所有行数据也是够对所有事务可见。
pd_lower:空闲空间开头位置在页中的偏移量,向页中插入行数据时,会从此位置开始向后分配新的行指针占用的空间
pd_upper:空闲空间结尾位置在页中的偏移量,向页中插入行数据时,会从此位置开始向前分配新的行数据占用的空间
pd_special:特殊空间开头位置在页中的偏移量.索引相关数据的开始位置,在数据文件中为空(即 pd_special =
pd_pagesize_version:标识前8位记录页大小,后八8记录布局版本号信息。版本号信息解释如下:
- 0:postgresql 7.3 之前的版本号是 0
- 1:代表postgresql 7.3 ~ 7.4
- 2:代表postgresql 8.0
- 3:代表postgresql 8.1 ~ 8.2
- 4:代表postgresql 8.3 及以后版本
pd_prune_xid:页面上最旧的xmax值,如果没有则为0。如果该位置有值,说明当前page中存在部分记录可以被vacuum回收。
items
由一个定长的头部(23 个字节)、一个可选的空值位图加填充位、一个可选的对象 id 域以及用户数据组成。
t_xmin:插入或者更新该行的事务id标志
t_xmax:删除或者锁定该行的事务id标志
t_field3:记录t_cid或t_xvac;
t_cid:如果这行在一个事务中被插入并删除,我们会存储一个复合的命令id,可以映射到真实的cmin, cmax,但只能在原始后端中使用本地状态。
t_xvac:xvac 只在老式的vacuum full中设置,它没有任何的命令子结构,所以不需要cmin,cmax (这要求老式vacuum full从不尝试移动cmin,cmax 依然有效的行,例如,正在插入或正在删除的行)
t_ctid:当前行的ctid或者指向更新后的行的ctid
t_infomask2:低11位用户标识列的数量,高5位用于hot技术及元组可见性的标志位;
目前使用的标志位共3个:
- 0x2000——heap_keys_updated:行数据被更新且列被修改了,或者行被删除了
- 0x4000——heap_hot_updated:行被以hot方式更新了;
- 0x8000——heap_only_tuple/heap_tuple_has_match:heap_only_tuple代表这是hot行,heap_tuple_has_match 是在 hash join 中临时使用的标志,只用于 hash 表中的 tuple,且不需要可见性信息,所以我们可以用一个可见性标志覆盖他。
t_infomask:用于标识元组当前的状态。
目前使用的标志如下:
- 0x0001——heap_hasnull:有包含null值的列
- 0x0002——heap_hasvarwidth:有变宽属性的列(varchar)
- 0x0004——heap_hasexternal:有存储在外部的列 (toast)
- 0x0008——heap_hasoid_old:有 oid 字段
- 0x0010——heap_xmax_keyshr_lock: xmax 具有 key-shared 锁
- 0x0020——heap_combocid:t_field3的值是t_cid
- 0x0040——heap_xmax_excl_lock:xmax 具有 exclusive 锁
- 0x0080——heap_xmax_lock_only:如果 xmax 域有效,那么仅仅是锁的拥有者
- 0x0100——heap_xmin_committed:xmin 对应的事务已经提交
- 0x0200——heap_xmin_invalid:xmin 对应的事务无效或者已经被终止
- 0x0400——heap_xmax_committed:xmax 对应的事务已经提交
- 0x0800——heap_xmax_invalid:xmax 对应的事务无效或者已经被终止了
- 0x1000——heap_xmax_is_multi:xmax 对应的事务是一个多段事务 id
- 0x2000——heap_updated: 这是数据行被更新后的版本
- 0x4000——heap_moved_off:被 9.0 之前的 vacuum full 命令移动到另外的地方了,为了兼容二进制程序升级而保留
- 0x8000——heap_moved_in:被 9.0 之前的 vacuum full 命令从别处移动过来的,也是为了兼容性而保留
还有4个复合状态:
- heap_xmax_shr_lock=heap_xmax_excl_lock | heap_xmax_keyshr_lock
- heap_lock_mask=heap_xmax_shr_lock|heap_xmax_excl_lock|heap_xmax_keyshr_lock
- heap_xmin_frozen=heap_xmin_committed|heap_xmin_invalid
- heap_moved=heap_moved_off| heap_moved_in
t_hoff:指从items项的起始位置到用户数据实际所在位置的长度
null bitmap:当元组中存在空值时,会出现空值位图,每个字段占一位。
padding space:填充位,将null bitmap补充到maxalign的倍数,maxalign的值一般为8。
oid:如果表启用了with oids选项,items中还会有一个4字节的oid记录。
tuple data:行数据
查看页内容的工具
pageinspect扩展
安装pageinspect扩展
使用pageinspect扩展之前,需要在数据库中加载扩展
create extension pageinspect;
pageinspect扩展提供了很多查看页内容的相关函数,具体可参考文档:
https://www.postgresql.org/docs/13/pageinspect.html
使用举例
查看表t的第0号页的页头信息:
postgres=# select * from page_header(get_raw_page('t','main',0));
lsn | checksum | flags | lower | upper | special | pagesize | version | prune_xid
------------ ---------- ------- ------- ------- --------- ---------- --------- -----------
1/51015d20 | 29528 | 1 | 776 | 792 | 8192 | 8192 | 4 | 1689
(1 row)
查看表t的第0号页中行数据相关信息:
postgres=# select * from heap_page_items(get_raw_page('t',0));
lp | lp_off | lp_flags | lp_len | t_xmin | t_xmax | t_field3 | t_ctid | t_infomask2 | t_infomask | t_hoff | t_bits | t_oid | t_data
----- -------- ---------- -------- -------- -------- ---------- --------- ------------- ------------ -------- -------- ------- ----------------------------
1 | 16 | 2 | 0 | | | | | | | | | |
2 | 832 | 1 | 36 | 1685 | 0 | 0 | (0,2) | 2 | 2050 | 24 | | | \x0f7570646174650030010000
3 | 2032 | 1 | 36 | 1665 | 0 | 0 | (0,3) | 2 | 2306 | 24 | | | \x0f757064617465002d010000
4 | 8112 | 1 | 36 | 1655 | 0 | 0 | (0,4) | 2 | 2306 | 24 | | | \x0f7570646174650058010000
5 | 8072 | 1 | 36 | 1655 | 0 | 0 | (0,5) | 2 | 2306 | 24 | | | \x0f7570646174650059010000
6 | 8032 | 1 | 36 | 1655 | 0 | 0 | (0,6) | 2 | 2306 | 24 | | | \x0f757064617465005a010000
7 | 7992 | 1 | 36 | 1655 | 0 | 0 | (0,7) | 2 | 2306 | 24 | | | \x0f757064617465005b010000
8 | 7952 | 1 | 36 | 1655 | 0 | 0 | (0,8) | 2 | 2306 | 24 | | | \x0f757064617465005c010000
9 | 7912 | 1 | 36 | 1655 | 0 | 0 | (0,9) | 2 | 2306 | 24 | | | \x0f757064617465005d010000
10 | 7872 | 1 | 36 | 1655 | 0 | 0 | (0,10) | 2 | 2306 | 24 | | | \x0f757064617465005e010000
11 | 7832 | 1 | 36 | 1655 | 0 | 0 | (0,11) | 2 | 2306 | 24 | | | \x0f757064617465005f010000
12 | 7792 | 1 | 36 | 1655 | 0 | 0 | (0,12) | 2 | 2306 | 24 | | | \x0f7570646174650060010000
13 | 7752 | 1 | 36 | 1655 | 0 | 0 | (0,13) | 2 | 2306 | 24 | | | \x0f7570646174650061010000
14 | 7712 | 1 | 36 | 1655 | 0 | 0 | (0,14) | 2 | 2306 | 24 | | | \x0f7570646174650062010000
15 | 7672 | 1 | 36 | 1655 | 0 | 0 | (0,15) | 2 | 2306 | 24 | | | \x0f7570646174650063010000
16 | 872 | 1 | 36 | 1669 | 0 | 0 | (0,16) | 32770 | 10498 | 24 | | | \x0f696e7365727400f78a0100
17 | 7632 | 1 | 36 | 1655 | 0 | 0 | (0,17) | 2 | 2306 | 24 | | | \x0f7570646174650064010000
18 | 7592 | 1 | 36 | 1655 | 0 | 0 | (0,18) | 2 | 2306 | 24 | | | \x0f7570646174650065010000
19 | 7552 | 1 | 36 | 1655 | 0 | 0 | (0,19) | 2 | 2306 | 24 | | | \x0f7570646174650066010000
20 | 7512 | 1 | 36 | 1655 | 0 | 0 | (0,20) | 2 | 2306 | 24 | | | \x0f7570646174650067010000
21 | 7472 | 1 | 36 | 1655 | 0 | 0 | (0,21) | 2 | 2306 | 24 | | | \x0f7570646174650068010000
22 | 7432 | 1 | 36 | 1655 | 0 | 0 | (0,22) | 2 | 2306 | 24 | | | \x0f7570646174650069010000
23 | 7392 | 1 | 36 | 1655 | 0 | 0 | (0,23) | 2 | 2306 | 24 | | | \x0f757064617465006a010000
24 | 7352 | 1 | 36 | 1655 | 0 | 0 | (0,24) | 2 | 2306 | 24 | | | \x0f757064617465006b010000
25 | 7312 | 1 | 36 | 1655 | 0 | 0 | (0,25) | 2 | 2306 | 24 | | | \x0f757064617465006c010000
26 | 7272 | 1 | 36 | 1655 | 0 | 0 | (0,26) | 2 | 2306 | 24 | | | \x0f757064617465006d010000
27 | 7232 | 1 | 36 | 1655 | 0 | 0 | (0,27) | 2 | 2306 | 24 | | | \x0f757064617465006e010000
28 | 7192 | 1 | 36 | 1655 | 0 | 0 | (0,28) | 2 | 2306 | 24 | | | \x0f757064617465006f010000
29 | 7152 | 1 | 36 | 1655 | 0 | 0 | (0,29) | 2 | 2306 | 24 | | | \x0f7570646174650070010000
30 | 7112 | 1 | 36 | 1655 | 0 | 0 | (0,30) | 2 | 2306 | 24 | | | \x0f7570646174650071010000
31 | 7072 | 1 | 36 | 1655 | 0 | 0 | (0,31) | 2 | 2306 | 24 | | | \x0f7570646174650072010000
32 | 7032 | 1 | 36 | 1655 | 0 | 0 | (0,32) | 2 | 2306 | 24 | | | \x0f7570646174650073010000
33 | 6992 | 1 | 36 | 1655 | 0 | 0 | (0,33) | 2 | 2306 | 24 | | | \x0f7570646174650074010000
34 | 6952 | 1 | 36 | 1655 | 0 | 0 | (0,34) | 2 | 2306 | 24 | | | \x0f7570646174650075010000
35 | 6912 | 1 | 36 | 1655 | 0 | 0 | (0,35) | 2 | 2306 | 24 | | | \x0f7570646174650076010000
36 | 6872 | 1 | 36 | 1655 | 0 | 0 | (0,36) | 2 | 2306 | 24 | | | \x0f7570646174650077010000
37 | 6832 | 1 | 36 | 1655 | 0 | 0 | (0,37) | 2 | 2306 | 24 | | | \x0f7570646174650078010000
38 | 6792 | 1 | 36 | 1655 | 0 | 0 | (0,38) | 2 | 2306 | 24 | | | \x0f7570646174650079010000
39 | 6752 | 1 | 36 | 1655 | 0 | 0 | (0,39) | 2 | 2306 | 24 | | | \x0f757064617465007a010000
40 | 6712 | 1 | 36 | 1655 | 0 | 0 | (0,40) | 2 | 2306 | 24 | | | \x0f757064617465007b010000
41 | 6672 | 1 | 36 | 1655 | 0 | 0 | (0,41) | 2 | 2306 | 24 | | | \x0f757064617465007c010000
42 | 6632 | 1 | 36 | 1655 | 0 | 0 | (0,42) | 2 | 2306 | 24 | | | \x0f757064617465007d010000
43 | 6592 | 1 | 36 | 1655 | 0 | 0 | (0,43) | 2 | 2306 | 24 | | | \x0f757064617465007e010000
44 | 6552 | 1 | 36 | 1655 | 0 | 0 | (0,44) | 2 | 2306 | 24 | | | \x0f757064617465007f010000
45 | 6512 | 1 | 36 | 1655 | 0 | 0 | (0,45) | 2 | 2306 | 24 | | | \x0f7570646174650080010000
46 | 6472 | 1 | 36 | 1655 | 0 | 0 | (0,46) | 2 | 2306 | 24 | | | \x0f7570646174650081010000
47 | 6432 | 1 | 36 | 1655 | 0 | 0 | (0,47) | 2 | 2306 | 24 | | | \x0f7570646174650082010000
48 | 6392 | 1 | 36 | 1655 | 0 | 0 | (0,48) | 2 | 2306 | 24 | | | \x0f7570646174650083010000
49 | 6352 | 1 | 36 | 1655 | 0 | 0 | (0,49) | 2 | 2306 | 24 | | | \x0f7570646174650084010000
50 | 6312 | 1 | 36 | 1655 | 0 | 0 | (0,50) | 2 | 2306 | 24 | | | \x0f7570646174650085010000
51 | 6272 | 1 | 36 | 1655 | 0 | 0 | (0,51) | 2 | 2306 | 24 | | | \x0f7570646174650086010000
52 | 6232 | 1 | 36 | 1655 | 0 | 0 | (0,52) | 2 | 2306 | 24 | | | \x0f7570646174650087010000
53 | 6192 | 1 | 36 | 1655 | 0 | 0 | (0,53) | 2 | 2306 | 24 | | | \x0f7570646174650088010000
54 | 6152 | 1 | 36 | 1655 | 0 | 0 | (0,54) | 2 | 2306 | 24 | | | \x0f7570646174650089010000
55 | 6112 | 1 | 36 | 1655 | 0 | 0 | (0,55) | 2 | 2306 | 24 | | | \x0f757064617465008a010000
56 | 6072 | 1 | 36 | 1655 | 0 | 0 | (0,56) | 2 | 2306 | 24 | | | \x0f757064617465008b010000
57 | 6032 | 1 | 36 | 1655 | 0 | 0 | (0,57) | 2 | 2306 | 24 | | | \x0f757064617465008c010000
58 | 5992 | 1 | 36 | 1655 | 0 | 0 | (0,58) | 2 | 2306 | 24 | | | \x0f757064617465008d010000
59 | 5952 | 1 | 36 | 1655 | 0 | 0 | (0,59) | 2 | 2306 | 24 | | | \x0f757064617465008e010000
60 | 5912 | 1 | 36 | 1655 | 0 | 0 | (0,60) | 2 | 2306 | 24 | | | \x0f757064617465008f010000
61 | 5872 | 1 | 36 | 1655 | 0 | 0 | (0,61) | 2 | 2306 | 24 | | | \x0f7570646174650090010000
62 | 5832 | 1 | 36 | 1655 | 0 | 0 | (0,62) | 2 | 2306 | 24 | | | \x0f7570646174650091010000
63 | 5792 | 1 | 36 | 1655 | 0 | 0 | (0,63) | 2 | 2306 | 24 | | | \x0f7570646174650092010000
64 | 5752 | 1 | 36 | 1655 | 0 | 0 | (0,64) | 2 | 2306 | 24 | | | \x0f7570646174650093010000
65 | 5712 | 1 | 36 | 1655 | 0 | 0 | (0,65) | 2 | 2306 | 24 | | | \x0f7570646174650094010000
66 | 5672 | 1 | 36 | 1655 | 0 | 0 | (0,66) | 2 | 2306 | 24 | | | \x0f7570646174650095010000
67 | 5632 | 1 | 36 | 1655 | 0 | 0 | (0,67) | 2 | 2306 | 24 | | | \x0f7570646174650096010000
68 | 5592 | 1 | 36 | 1655 | 0 | 0 | (0,68) | 2 | 2306 | 24 | | | \x0f7570646174650097010000
69 | 5552 | 1 | 36 | 1655 | 0 | 0 | (0,69) | 2 | 2306 | 24 | | | \x0f7570646174650098010000
70 | 5512 | 1 | 36 | 1655 | 0 | 0 | (0,70) | 2 | 2306 | 24 | | | \x0f7570646174650099010000
71 | 5472 | 1 | 36 | 1655 | 0 | 0 | (0,71) | 2 | 2306 | 24 | | | \x0f757064617465009a010000
72 | 5432 | 1 | 36 | 1655 | 0 | 0 | (0,72) | 2 | 2306 | 24 | | | \x0f757064617465009b010000
73 | 5392 | 1 | 36 | 1655 | 0 | 0 | (0,73) | 2 | 2306 | 24 | | | \x0f757064617465009c010000
74 | 5352 | 1 | 36 | 1655 | 0 | 0 | (0,74) | 2 | 2306 | 24 | | | \x0f757064617465009d010000
75 | 5312 | 1 | 36 | 1655 | 0 | 0 | (0,75) | 2 | 2306 | 24 | | | \x0f757064617465009e010000
76 | 5272 | 1 | 36 | 1655 | 0 | 0 | (0,76) | 2 | 2306 | 24 | | | \x0f757064617465009f010000
77 | 5232 | 1 | 36 | 1655 | 0 | 0 | (0,77) | 2 | 2306 | 24 | | | \x0f75706461746500a0010000
78 | 5192 | 1 | 36 | 1655 | 0 | 0 | (0,78) | 2 | 2306 | 24 | | | \x0f75706461746500a1010000
79 | 5152 | 1 | 36 | 1655 | 0 | 0 | (0,79) | 2 | 2306 | 24 | | | \x0f75706461746500a2010000
80 | 5112 | 1 | 36 | 1655 | 0 | 0 | (0,80) | 2 | 2306 | 24 | | | \x0f75706461746500a3010000
81 | 5072 | 1 | 36 | 1655 | 0 | 0 | (0,81) | 2 | 2306 | 24 | | | \x0f75706461746500a4010000
82 | 5032 | 1 | 36 | 1655 | 0 | 0 | (0,82) | 2 | 2306 | 24 | | | \x0f75706461746500a5010000
83 | 4992 | 1 | 36 | 1655 | 0 | 0 | (0,83) | 2 | 2306 | 24 | | | \x0f75706461746500a6010000
84 | 4952 | 1 | 36 | 1655 | 0 | 0 | (0,84) | 2 | 2306 | 24 | | | \x0f75706461746500a7010000
85 | 4912 | 1 | 36 | 1655 | 0 | 0 | (0,85) | 2 | 2306 | 24 | | | \x0f75706461746500a8010000
86 | 4872 | 1 | 36 | 1655 | 0 | 0 | (0,86) | 2 | 2306 | 24 | | | \x0f75706461746500a9010000
87 | 4832 | 1 | 36 | 1655 | 0 | 0 | (0,87) | 2 | 2306 | 24 | | | \x0f75706461746500aa010000
88 | 4792 | 1 | 36 | 1655 | 0 | 0 | (0,88) | 2 | 2306 | 24 | | | \x0f75706461746500ab010000
89 | 4752 | 1 | 36 | 1655 | 0 | 0 | (0,89) | 2 | 2306 | 24 | | | \x0f75706461746500ac010000
90 | 4712 | 1 | 36 | 1655 | 0 | 0 | (0,90) | 2 | 2306 | 24 | | | \x0f75706461746500ad010000
91 | 4672 | 1 | 36 | 1655 | 0 | 0 | (0,91) | 2 | 2306 | 24 | | | \x0f75706461746500ae010000
92 | 4632 | 1 | 36 | 1655 | 0 | 0 | (0,92) | 2 | 2306 | 24 | | | \x0f75706461746500af010000
93 | 4592 | 1 | 36 | 1655 | 0 | 0 | (0,93) | 2 | 2306 | 24 | | | \x0f75706461746500b0010000
94 | 4552 | 1 | 36 | 1655 | 0 | 0 | (0,94) | 2 | 2306 | 24 | | | \x0f75706461746500b1010000
95 | 4512 | 1 | 36 | 1655 | 0 | 0 | (0,95) | 2 | 2306 | 24 | | | \x0f75706461746500b2010000
96 | 4472 | 1 | 36 | 1655 | 0 | 0 | (0,96) | 2 | 2306 | 24 | | | \x0f75706461746500b3010000
97 | 4432 | 1 | 36 | 1655 | 0 | 0 | (0,97) | 2 | 2306 | 24 | | | \x0f75706461746500b4010000
98 | 4392 | 1 | 36 | 1655 | 0 | 0 | (0,98) | 2 | 2306 | 24 | | | \x0f75706461746500b5010000
99 | 4352 | 1 | 36 | 1655 | 0 | 0 | (0,99) | 2 | 2306 | 24 | | | \x0f75706461746500b6010000
100 | 4312 | 1 | 36 | 1655 | 0 | 0 | (0,100) | 2 | 2306 | 24 | | | \x0f75706461746500b7010000
101 | 4272 | 1 | 36 | 1655 | 0 | 0 | (0,101) | 2 | 2306 | 24 | | | \x0f75706461746500b8010000
102 | 4232 | 1 | 36 | 1655 | 0 | 0 | (0,102) | 2 | 2306 | 24 | | | \x0f75706461746500b9010000
103 | 187 | 2 | 0 | | | | | | | | | |
104 | 1992 | 1 | 36 | 1665 | 0 | 0 | (0,104) | 2 | 2306 | 24 | | | \x0f757064617465002e010000
105 | 4192 | 1 | 36 | 1655 | 0 | 0 | (0,105) | 2 | 2306 | 24 | | | \x0f75706461746500ba010000
106 | 4152 | 1 | 36 | 1655 | 0 | 0 | (0,106) | 2 | 2306 | 24 | | | \x0f75706461746500bb010000
107 | 4112 | 1 | 36 | 1655 | 0 | 0 | (0,107) | 2 | 2306 | 24 | | | \x0f75706461746500bc010000
108 | 4072 | 1 | 36 | 1655 | 0 | 0 | (0,108) | 2 | 2306 | 24 | | | \x0f75706461746500bd010000
109 | 4032 | 1 | 36 | 1655 | 0 | 0 | (0,109) | 2 | 2306 | 24 | | | \x0f75706461746500be010000
110 | 3992 | 1 | 36 | 1655 | 0 | 0 | (0,110) | 2 | 2306 | 24 | | | \x0f75706461746500bf010000
111 | 3952 | 1 | 36 | 1655 | 0 | 0 | (0,111) | 2 | 2306 | 24 | | | \x0f75706461746500c0010000
112 | 3912 | 1 | 36 | 1655 | 0 | 0 | (0,112) | 2 | 2306 | 24 | | | \x0f75706461746500c1010000
113 | 3872 | 1 | 36 | 1655 | 0 | 0 | (0,113) | 2 | 2306 | 24 | | | \x0f75706461746500c2010000
114 | 3832 | 1 | 36 | 1655 | 0 | 0 | (0,114) | 2 | 2306 | 24 | | | \x0f75706461746500c3010000
115 | 3792 | 1 | 36 | 1655 | 0 | 0 | (0,115) | 2 | 2306 | 24 | | | \x0f75706461746500c4010000
116 | 3752 | 1 | 36 | 1655 | 0 | 0 | (0,116) | 2 | 2306 | 24 | | | \x0f75706461746500c5010000
117 | 3712 | 1 | 36 | 1655 | 0 | 0 | (0,117) | 2 | 2306 | 24 | | | \x0f75706461746500c6010000
118 | 3672 | 1 | 36 | 1655 | 0 | 0 | (0,118) | 2 | 2306 | 24 | | | \x0f75706461746500c7010000
119 | 3632 | 1 | 36 | 1655 | 0 | 0 | (0,119) | 2 | 2306 | 24 | | | \x0f75706461746500c8010000
120 | 3592 | 1 | 36 | 1655 | 0 | 0 | (0,120) | 2 | 2306 | 24 | | | \x0f75706461746500c9010000
121 | 3552 | 1 | 36 | 1655 | 0 | 0 | (0,121) | 2 | 2306 | 24 | | | \x0f75706461746500ca010000
122 | 3512 | 1 | 36 | 1655 | 0 | 0 | (0,122) | 2 | 2306 | 24 | | | \x0f75706461746500cb010000
123 | 3472 | 1 | 36 | 1655 | 0 | 0 | (0,123) | 2 | 2306 | 24 | | | \x0f75706461746500cc010000
124 | 3432 | 1 | 36 | 1655 | 0 | 0 | (0,124) | 2 | 2306 | 24 | | | \x0f75706461746500cd010000
125 | 3392 | 1 | 36 | 1655 | 0 | 0 | (0,125) | 2 | 2306 | 24 | | | \x0f75706461746500ce010000
126 | 3352 | 1 | 36 | 1655 | 0 | 0 | (0,126) | 2 | 2306 | 24 | | | \x0f75706461746500cf010000
127 | 3312 | 1 | 36 | 1655 | 0 | 0 | (0,127) | 2 | 2306 | 24 | | | \x0f75706461746500d0010000
128 | 3272 | 1 | 36 | 1655 | 0 | 0 | (0,128) | 2 | 2306 | 24 | | | \x0f75706461746500d1010000
129 | 3232 | 1 | 36 | 1655 | 0 | 0 | (0,129) | 2 | 2306 | 24 | | | \x0f75706461746500d2010000
130 | 3192 | 1 | 36 | 1655 | 0 | 0 | (0,130) | 2 | 2306 | 24 | | | \x0f75706461746500d3010000
131 | 3152 | 1 | 36 | 1655 | 0 | 0 | (0,131) | 2 | 2306 | 24 | | | \x0f75706461746500d4010000
132 | 3112 | 1 | 36 | 1655 | 0 | 0 | (0,132) | 2 | 2306 | 24 | | | \x0f75706461746500d5010000
133 | 3072 | 1 | 36 | 1655 | 0 | 0 | (0,133) | 2 | 2306 | 24 | | | \x0f75706461746500d6010000
134 | 3032 | 1 | 36 | 1655 | 0 | 0 | (0,134) | 2 | 2306 | 24 | | | \x0f75706461746500d7010000
135 | 2992 | 1 | 36 | 1655 | 0 | 0 | (0,135) | 2 | 2306 | 24 | | | \x0f75706461746500d8010000
136 | 2952 | 1 | 36 | 1655 | 0 | 0 | (0,136) | 2 | 2306 | 24 | | | \x0f75706461746500d9010000
137 | 2912 | 1 | 36 | 1655 | 0 | 0 | (0,137) | 2 | 2306 | 24 | | | \x0f75706461746500da010000
138 | 2872 | 1 | 36 | 1655 | 0 | 0 | (0,138) | 2 | 2306 | 24 | | | \x0f75706461746500db010000
139 | 2832 | 1 | 36 | 1655 | 0 | 0 | (0,139) | 2 | 2306 | 24 | | | \x0f75706461746500dc010000
140 | 2792 | 1 | 36 | 1655 | 0 | 0 | (0,140) | 2 | 2306 | 24 | | | \x0f75706461746500dd010000
141 | 2752 | 1 | 36 | 1655 | 0 | 0 | (0,141) | 2 | 2306 | 24 | | | \x0f75706461746500de010000
142 | 2712 | 1 | 36 | 1655 | 0 | 0 | (0,142) | 2 | 2306 | 24 | | | \x0f75706461746500df010000
143 | 2672 | 1 | 36 | 1655 | 0 | 0 | (0,143) | 2 | 2306 | 24 | | | \x0f75706461746500e0010000
144 | 2632 | 1 | 36 | 1655 | 0 | 0 | (0,144) | 2 | 2306 | 24 | | | \x0f75706461746500e1010000
145 | 2592 | 1 | 36 | 1655 | 0 | 0 | (0,145) | 2 | 2306 | 24 | | | \x0f75706461746500e2010000
146 | 2552 | 1 | 36 | 1655 | 0 | 0 | (0,146) | 2 | 2306 | 24 | | | \x0f75706461746500e3010000
147 | 2512 | 1 | 36 | 1655 | 0 | 0 | (0,147) | 2 | 2306 | 24 | | | \x0f75706461746500e4010000
148 | 2472 | 1 | 36 | 1655 | 0 | 0 | (0,148) | 2 | 2306 | 24 | | | \x0f75706461746500e5010000
149 | 2432 | 1 | 36 | 1655 | 0 | 0 | (0,149) | 2 | 2306 | 24 | | | \x0f75706461746500e6010000
150 | 2392 | 1 | 36 | 1655 | 0 | 0 | (0,150) | 2 | 2306 | 24 | | | \x0f75706461746500e7010000
151 | 2352 | 1 | 36 | 1655 | 0 | 0 | (0,151) | 2 | 2306 | 24 | | | \x0f75706461746500e8010000
152 | 2312 | 1 | 36 | 1655 | 0 | 0 | (0,152) | 2 | 2306 | 24 | | | \x0f75706461746500e9010000
153 | 2272 | 1 | 36 | 1655 | 0 | 0 | (0,153) | 2 | 2306 | 24 | | | \x0f75706461746500ea010000
154 | 2232 | 1 | 36 | 1655 | 0 | 0 | (0,154) | 2 | 2306 | 24 | | | \x0f75706461746500eb010000
155 | 2192 | 1 | 36 | 1655 | 0 | 0 | (0,155) | 2 | 2306 | 24 | | | \x0f75706461746500ec010000
156 | 2152 | 1 | 36 | 1655 | 0 | 0 | (0,156) | 2 | 2306 | 24 | | | \x0f75706461746500ed010000
157 | 2112 | 1 | 36 | 1655 | 0 | 0 | (0,157) | 2 | 2306 | 24 | | | \x0f75706461746500ee010000
158 | 2072 | 1 | 36 | 1655 | 0 | 0 | (0,158) | 2 | 2306 | 24 | | | \x0f75706461746500ef010000
159 | 1952 | 1 | 36 | 1665 | 0 | 0 | (0,159) | 2 | 2306 | 24 | | | \x0f757064617465002f010000
160 | 1912 | 1 | 36 | 1665 | 0 | 0 | (0,160) | 2 | 2306 | 24 | | | \x0f7570646174650030010000
161 | 1872 | 1 | 36 | 1665 | 0 | 0 | (0,161) | 2 | 2306 | 24 | | | \x0f7570646174650031010000
162 | 1832 | 1 | 36 | 1665 | 0 | 0 | (0,162) | 2 | 2306 | 24 | | | \x0f7570646174650032010000
163 | 1792 | 1 | 36 | 1665 | 0 | 0 | (0,163) | 2 | 2306 | 24 | | | \x0f7570646174650033010000
164 | 1752 | 1 | 36 | 1665 | 0 | 0 | (0,164) | 2 | 2306 | 24 | | | \x0f7570646174650034010000
165 | 1712 | 1 | 36 | 1665 | 0 | 0 | (0,165) | 2 | 2306 | 24 | | | \x0f7570646174650035010000
166 | 1672 | 1 | 36 | 1665 | 0 | 0 | (0,166) | 2 | 2306 | 24 | | | \x0f7570646174650036010000
167 | 1632 | 1 | 36 | 1665 | 0 | 0 | (0,167) | 2 | 2306 | 24 | | | \x0f7570646174650037010000
168 | 1592 | 1 | 36 | 1665 | 0 | 0 | (0,168) | 2 | 2306 | 24 | | | \x0f7570646174650038010000
169 | 1552 | 1 | 36 | 1665 | 0 | 0 | (0,169) | 2 | 2306 | 24 | | | \x0f7570646174650039010000
170 | 1512 | 1 | 36 | 1665 | 0 | 0 | (0,170) | 2 | 2306 | 24 | | | \x0f757064617465003a010000
171 | 1472 | 1 | 36 | 1665 | 0 | 0 | (0,171) | 2 | 2306 | 24 | | | \x0f757064617465003b010000
172 | 1432 | 1 | 36 | 1665 | 0 | 0 | (0,172) | 2 | 2306 | 24 | | | \x0f757064617465003c010000
173 | 1392 | 1 | 36 | 1665 | 0 | 0 | (0,173) | 2 | 2306 | 24 | | | \x0f757064617465003d010000
174 | 1352 | 1 | 36 | 1665 | 0 | 0 | (0,174) | 2 | 2306 | 24 | | | \x0f757064617465003e010000
175 | 1312 | 1 | 36 | 1665 | 0 | 0 | (0,175) | 2 | 2306 | 24 | | | \x0f757064617465003f010000
176 | 1272 | 1 | 36 | 1665 | 0 | 0 | (0,176) | 2 | 2306 | 24 | | | \x0f7570646174650040010000
177 | 1232 | 1 | 36 | 1665 | 0 | 0 | (0,177) | 2 | 2306 | 24 | | | \x0f7570646174650041010000
178 | 1192 | 1 | 36 | 1665 | 0 | 0 | (0,178) | 2 | 2306 | 24 | | | \x0f7570646174650042010000
179 | 1152 | 1 | 36 | 1665 | 0 | 0 | (0,179) | 2 | 2306 | 24 | | | \x0f7570646174650043010000
180 | 792 | 1 | 36 | 1686 | 0 | 0 | (0,180) | 2 | 2050 | 24 | | | \x0f7570646174650030010000
181 | 1112 | 1 | 36 | 1665 | 0 | 0 | (0,181) | 2 | 2306 | 24 | | | \x0f7570646174650045010000
182 | 1072 | 1 | 36 | 1665 | 0 | 0 | (0,182) | 2 | 2306 | 24 | | | \x0f7570646174650046010000
183 | 1032 | 1 | 36 | 1665 | 0 | 0 | (0,183) | 2 | 2306 | 24 | | | \x0f7570646174650047010000
184 | 992 | 1 | 36 | 1665 | 0 | 0 | (0,184) | 2 | 2306 | 24 | | | \x0f7570646174650048010000
185 | 952 | 1 | 36 | 1665 | 0 | 0 | (0,185) | 2 | 2306 | 24 | | | \x0f7570646174650049010000
186 | 912 | 1 | 36 | 1665 | 0 | 0 | (0,186) | 2 | 2306 | 24 | | | \x0f757064617465004a010000
187 | 8152 | 1 | 36 | 1646 | 0 | 0 | (0,187) | 32770 | 10498 | 24 | | | \x0f75706461746500a1860100
188 | 0 | 0 | 0 | | | | | | | | | |
(188 rows)
pg_filedump工具
安装pg_filedump工具
su - postgres git clone git://git.postgresql.org/git/pg_filedump.git cd pg_filedump make && make install
使用pg_filedump工具
[postgres@mogdb1 13580]$ pg_filedump -d varchar,int -i 16977|more ******************************************************************* * postgresql file/block formatted dump utility * * file: 16977 * options used: -d varchar,int -i ******************************************************************* block 0 ********************************************************
----- block offset: 0x00000000 offsets: lower 776 (0x0308) block: size 8192 version 4 upper 792 (0x0318) lsn: logid 1 recoff 0x51015d20 special 8192 (0x2000) items: 188 free space: 16 checksum: 0x1b45 prune xid: 0x00000699 flags: 0x0001 (has_free_lines) length (including item array): 776 ----- item 1 -- length: 0 offset: 16 (0x0010) flags: redirect item 2 -- length: 36 offset: 832 (0x0340) flags: normal xmin: 1685 xmax: 0 cid|xvac: 0 block id: 0 linp index: 2 attributes: 2 size: 24 infomask: 0x0902 (hasvarwidth|xmin_committed|xmax_invalid) copy: update 304 item 3 -- length: 36 offset: 2032 (0x07f0) flags: normal xmin: 1665 xmax: 1689 cid|xvac: 0 block id: 0 linp index: 3 attributes: 2 size: 24 infomask: 0x0102 (hasvarwidth|xmin_committed|keys_updated) copy: update 301 item 4 -- length: 36 offset: 8112 (0x1fb0) flags: normal xmin: 1655 xmax: 0 cid|xvac: 0 block id: 0 linp index: 4 attributes: 2 size: 24 infomask: 0x0902 (hasvarwidth|xmin_committed|xmax_invalid) copy: update 344 item 5 -- length: 36 offset: 8072 (0x1f88) flags: normal xmin: 1655 xmax: 0 cid|xvac: 0 block id: 0 linp index: 5 attributes: 2 size: 24 infomask: 0x0902 (hasvarwidth|xmin_committed|xmax_invalid) copy: update 345 item 6 -- length: 36 offset: 8032 (0x1f60) flags: normal xmin: 1655 xmax: 0 cid|xvac: 0 block id: 0 linp index: 6 attributes: 2 size: 24 infomask: 0x0902 (hasvarwidth|xmin_committed|xmax_invalid) copy: update 346 item 7 -- length: 36 offset: 7992 (0x1f38) flags: normal xmin: 1655 xmax: 0 cid|xvac: 0 block id: 0 linp index: 7 attributes: 2 size: 24 infomask: 0x0902 (hasvarwidth|xmin_committed|xmax_invalid) copy: update 347 item 8 -- length: 36 offset: 7952 (0x1f10) flags: normal xmin: 1655 xmax: 0 cid|xvac: 0 block id: 0 linp index: 8 attributes: 2 size: 24 infomask: 0x0902 (hasvarwidth|xmin_committed|xmax_invalid)
通过观察页内数据的变化,有助于我们理解pg数据库中mvcc,vacuum以及hot特性的原理。