就地升级:存储

来自 PostgreSQL wiki
跳转到导航跳转到搜索



存储

页面布局版本

PostgreSQL 版本
7.4 8.0 8.1 8.2 8.3 8.4devel
布局版本 1 2 3 3 4 4
头大小 [B] 20 20 20 20 24 24
元组头大小 [B] 23 27 27 27 23 23
元组头对齐大小 [B]

(MAX_ALIGN 4B/8B)

24/24 28/32 28/32 28/32 24/24 24/24
元组头对齐大小 [B]

带有空位数组 (MAX_ALIGN=4B/8B)

28/32 32/32 32/32 32/32 28/32 28/32
最大 TOAST 块大小 [B]

(MAX_ALIGN=4B/8B)

?/? ?? 1994/1986 1994/1986 2000/1996 2000/1996

页面头

版本 1

00       01       02       03       04       05       06       07       08       09       10       11       12       13       14       15          
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
|                          (XLogPtr) pd_lsn                             |         (uint32)pd_sui            |(uint16)pd_lower |(uint16)pd_upper |
|    (uint32)XLogPtr.xlogid         |      (uint32)XLogPtr.xrecoff      |                                   |                 |                 |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+

16       17       18       19       20   
+--------+--------+--------+--------+-------->
|    (uint16)     |pd_pagesize_\    | pd_linp[]			     
|   pd_special    |version(uint16)  |        
+--------+--------+--------+--------+-------->


版本 2 和 3

注意:页面头对于页面布局 2 和 3 都是相同的。

00       01       02       03       04       05       06       07       08       09       10       11       12       13       14       15          
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
|                          (XLogPtr) pd_lsn                             |         (uint32)pd_tli            |(uint16)pd_lower |(uint16)pd_upper |
|    (uint32)XLogPtr.xlogid         |      (uint32)XLogPtr.xrecoff      |                                   |                 |                 |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+

16       17       18       19       20   
+--------+--------+--------+--------+-------->
|     (uint16)    |pd_pagesize_\    | pd_linp[]			     
|    pd_special   |version(uint16)  |        
+--------+--------+--------+--------+-------->

版本 4

00       01       02       03       04       05       06       07       08       09       10       11       12       13       14       15          
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
|                          (XLogPtr) pd_lsn                             | (uint16)pd_tli  |(uint16)pd_flags |(uint16)pd_lower |(uint16)pd_upper |
|    (uint32)XLogPtr.xlogid         |      (uint32)XLogPtr.xrecoff      |                 |                 |                 |                 |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+

16       17       18       19       20       21       22       23       24 
+--------+--------+--------+--------+--------+--------+--------+--------+-------->
|    (uint16)     |pd_pagesize_\    |       (uint32)pd_prune_xid        | pd_linp[]			     
|   pd_special    |version(uint16)  |                                   |
+--------+--------+--------+--------+--------+--------+--------+--------+-------->

元组头

版本 1

00       01       02       03       04       05       06       07       08       09       10       11       12       13       14       15    
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
|         (uint32)t_xmin            |           (union)t_field2         |           (union)t_field3         |      (ItemPointerData)t_ctid                          
|                                   |   (uint32)t_cmin/(uint32)t_xmax   |   (uint32)t_cmax/(uint32)t_xvac   |          (uint32)ip_blkid         |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+

16       17       18       19       20       21       22       23   
+--------+--------+--------+--------+--------+--------+--------+-------->
   ... t_ctid     | (int16)t_natts  |     (uint16)    |(uint8) |        
|(uint16)ip_posid |                 |    t_infomask   | t_hoff |t_bits[]
+--------+--------+--------+--------+--------+--------+--------+-------->

版本 2 和 3

注意:元组头结构对于版本 2 和 3 来说是相同的,但 infomask 内容略有不同。

00       01       02       03       04       05       06       07       08       09       10       11       12       13       14       15    
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
|         (uint32)t_xmin            |           (uint32)t_cmin          |          (uint32)t_xmax           |           (union)t_field4         |      
|                                   |                                   |                                   |   (uint32)t_cmax/(uint32)t_xvac   |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+

16       17       18       19       20       21       22       23       24       25       26       27  
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+-------->
|                (ItemPointerData)t_ctid              | (int16)t_natts  |     (uint16)    |(uint8) |        
|          (uint32)ip_blkid         |(uint16)ip_posid |                 |    t_infomask   | t_hoff |t_bits[]
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+-------->

版本 4

00       01       02       03       04       05       06       07       08       09       10       11       12       13       14       15    
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+
|         (uint32)t_xmin            |           (uint32)t_xmax          |           (union)t_field3         |      (ItemPointerData)t_ctid                          
|                                   |                                   |   (uint32)t_cid/(uint32)t_xvac    |          (uint32)ip_blkid         |
+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+--------+

16       17       18       19       20       21       22       23   
+--------+--------+--------+--------+--------+--------+--------+-------->
   ... t_ctid     |     (int16)     |     (uint16)    |(uint8) |        
|(uint16)ip_posid |   t_infomask2   |    t_infomask   | t_hoff |t_bits[]
+--------+--------+--------+--------+--------+--------+--------+-------->

元组信息掩码

注意:页面布局 4 引入了第二个 infomask。

               01                         02                         03                         04           
   +--------------------------+--------------------------+--------------------------+--------------------------+
00 |      HEAP_HASNULL        |      HEAP_HASNULL        |      HEAP_HASNULL        |      HEAP_HASNULL        |
   +--------------------------+--------------------------+--------------------------+--------------------------+
01 |     HEAP_HASVARWIDTH     |     HEAP_HASVARWIDTH     |     HEAP_HASVARWIDTH     |     HEAP_HASVARWIDTH     |
   +--------------------------+--------------------------+--------------------------+--------------------------+
02 |     HEAP_HASEXTERNAL     |     HEAP_HASEXTERNAL     |     HEAP_HASEXTERNAL     |     HEAP_HASEXTERNAL     |
   +--------------------------+--------------------------+--------------------------+--------------------------+
03 |    HEAP_HASCOMPRESSED    |    HEAP_HASCOMPRESSED    |    HEAP_HASCOMPRESSED    |       HEAP_HASOID        |
   +--------------------------+--------------------------+--------------------------+--------------------------+
04 |       HEAP_HASOID        |       HEAP_HASOID        |       HEAP_HASOID        |         (UNUSED)         | 
   +--------------------------+--------------------------+--------------------------+--------------------------+
05 |        (UNUSED)          |         (UNUSED)         |        (UNUSED)          |       HEAP_COMBOCID      |  
   +--------------------------+--------------------------+--------------------------+--------------------------+
06 |    HEAP_XMAX_IS_XMIN     |         (UNUSED)         |   HEAP_XMAX_EXCL_LOCK    |   HEAP_XMAX_EXCL_LOCK    |
   +--------------------------+--------------------------+--------------------------+--------------------------+
07 |   HEAP_XMAX_UNLOGGED     |   HEAP_XMAX_UNLOGGED     |  HEAP_XMAX_SHARED_LOCK   |  HEAP_XMAX_SHARED_LOCK   |
   +--------------------------+--------------------------+--------------------------+--------------------------+
08 |   HEAP_XMIN_COMMITTED    |   HEAP_XMIN_COMMITTED    |   HEAP_XMIN_COMMITTED    |   HEAP_XMIN_COMMITTED    |
   +--------------------------+--------------------------+--------------------------+--------------------------+
09 |    HEAP_XMIN_INVALID     |    HEAP_XMIN_INVALID     |    HEAP_XMIN_INVALID     |    HEAP_XMIN_INVALID     |
   +--------------------------+--------------------------+--------------------------+--------------------------+
10 |   HEAP_XMAX_COMMITTED    |   HEAP_XMAX_COMMITTED    |   HEAP_XMAX_COMMITTED    |   HEAP_XMAX_COMMITTED    |
   +--------------------------+--------------------------+--------------------------+--------------------------+
11 |    HEAP_XMAX_INVALID     |    HEAP_XMAX_INVALID     |    HEAP_XMAX_INVALID     |    HEAP_XMAX_INVALID     |
   +--------------------------+--------------------------+--------------------------+--------------------------+
12 |  HEAP_MARKED_FOR_UPDATE  |  HEAP_MARKED_FOR_UPDATE  |    HEAP_XMAX_IS_MULTI    |    HEAP_XMAX_IS_MULTI    |
   +--------------------------+--------------------------+--------------------------+--------------------------+
13 |       HEAP_UPDATED       |       HEAP_UPDATED       |       HEAP_UPDATED       |       HEAP_UPDATED       |
   +--------------------------+--------------------------+--------------------------+--------------------------+
14 |      HEAP_MOVED_OFF      |      HEAP_MOVED_OFF      |      HEAP_MOVED_OFF      |      HEAP_MOVED_OFF      |
   +--------------------------+--------------------------+--------------------------+--------------------------+
15 |      HEAP_MOVED_IN       |      HEAP_MOVED_IN       |      HEAP_MOVED_IN       |      HEAP_MOVED_IN       |
   +--------------------------+--------------------------+--------------------------+--------------------------+


Varlen 编码

图例
e ... 外部存储
c ... 压缩
s ... 大小

8.3 之前

大端字节序
ecss ssss :: ssss ssss :: ssss ssss :: ssss ssss

d2 34 56 78 is external compressed datum, size is 12345678B


小端字节序
ssss ssss :: ssss ssss :: ssss ssss :: ecss ssss

78 56 34 d2 is external compressed datum, size is 12345678B

8.3 及更高版本

大端字节序
0sss ssss                                        - uncompressed, unaligned data max 126 bytes long
1000 0000                                        - TOAST pointer
0css ssss :: ssss ssss :: ssss ssss :: ssss ssss - aligned data up to 1GB

7e          is internal 126 bytes unaligned long data
12 34 56 78 is internal uncompressed datum, size is 12345678B
52 34 56 78 is internal compressed datum, size is 12345678B


小端字节序
ssss sss0                                        - uncompressed, unaligned data max 126 bytes long
0000 0001                                        - TOAST pointer
ssss ssc0 :: ssss ssss :: ssss ssss :: ssss ssss - aligned data up to 1GB

FC          is internal 126 bytes unaligned long data
E0 59 D1 48 is internal uncompressed datum, size is 12345678B
E2 59 D1 48 is internal compressed datum, size is 12345678B