-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeadTupleHeaderData.c
More file actions
500 lines (427 loc) · 22.2 KB
/
Copy pathHeadTupleHeaderData.c
File metadata and controls
500 lines (427 loc) · 22.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
说明:
1. 内容参考pg9.5源码src/include/access/htup_details.h
2. 参考《PostgreSQL数据库内核分析》P59
3. 需要加载contrib/pageinspect
4. 参考:http://my.oschina.net/Suregogo/blog/176279
http://my.oschina.net/Suregogo/blog/595335?fromerr=4Ru4VQhW
HeadTupleHeaderData结构体:
struct HeapTupleHeaderData
{
union
{
HeapTupleFields t_heap;
DatumTupleFields t_datum;
} t_choice;
ItemPointerData t_ctid; /* current TID of this or newer tuple (or a
* speculative insertion token) */
/* Fields below here must match MinimalTupleData! */
uint16 t_infomask2; /* number of attributes + various flags */
uint16 t_infomask; /* various flag bits, see below */
uint8 t_hoff; /* sizeof header incl. bitmap, padding */
/* ^ - 23 bytes - ^ */
bits8 t_bits[FLEXIBLE_ARRAY_MEMBER]; /* bitmap of NULLs */
/* MORE DATA FOLLOWS AT END OF STRUCT */
};
通过pg_relation_filepath('tbname')找出其对应的表数据文件,通过hex 文件名 即可查看
下面简单画出该结构体示意图(由于hexdump每16个字节输出1行,所以下面也是16字节1行):
xmin(4bytes) xmax(4bytes) cmin/cmax(4bytes) ctid(4bytes+..)
ctid(..+2bytes) t_infomask2(2bytes) t_informask(2bytes) t_bits(1byte) t_hoff(1byte) values(...)
操作示例;
wln@iZ232ngsvp8Z:~> psql
psql (9.5beta1)
Type "help" for help.
postgres=# \d
List of relations
Schema | Name | Type | Owner
--------+------+-------+-------
public | c1 | table | wln
public | t1 | table | wln
public | t2 | table | wln
public | t4 | table | wln
(4 rows)
postgres=# select * from t2;
id1 | id2 | id3 | id4 | id5 | id6
-----+-----+-----+-----+-----+-----
1 | 2 | 3 | 4 | |
2 | 2 | 3 | 4 | |
3 | 2 | 3 | 4 | |
4 | 2 | 3 | 4 | |
5 | 2 | 3 | 4 | |
6 | 2 | 3 | 4 | |
7 | 2 | 3 | 4 | |
8 | 2 | 3 | 4 | |
9 | 2 | 3 | 4 | |
11 | | | | |
12 | | | | |
13 | | | | |
14 | | | | |
15 | | | | |
16 | | | | |
11 | 12 | 13 | 14 | 15 | 16
(16 rows)
postgres=# select pg_relation_filepath('t2');
pg_relation_filepath
----------------------
base/12974/41017
(1 row)
postgres=# select * from heap_page_items(get_raw_page('t2', 'main', 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
----+--------+----------+--------+--------+--------+----------+--------+-------------+------------+--------+----------+-------
1 | 8152 | 1 | 40 | 1320 | 0 | 0 | (0,1) | 6 | 2305 | 24 | 11110000 |
2 | 8112 | 1 | 40 | 1320 | 0 | 0 | (0,2) | 6 | 2305 | 24 | 11110000 |
3 | 8072 | 1 | 40 | 1320 | 0 | 0 | (0,3) | 6 | 2305 | 24 | 11110000 |
4 | 8032 | 1 | 40 | 1320 | 0 | 0 | (0,4) | 6 | 2305 | 24 | 11110000 |
5 | 7992 | 1 | 40 | 1320 | 0 | 0 | (0,5) | 6 | 2305 | 24 | 11110000 |
6 | 7952 | 1 | 40 | 1320 | 0 | 0 | (0,6) | 6 | 2305 | 24 | 11110000 |
7 | 7912 | 1 | 40 | 1320 | 0 | 0 | (0,7) | 6 | 2305 | 24 | 11110000 |
8 | 7872 | 1 | 40 | 1320 | 0 | 0 | (0,8) | 6 | 2305 | 24 | 11110000 |
9 | 7832 | 1 | 40 | 1320 | 0 | 0 | (0,9) | 6 | 2305 | 24 | 11110000 |
10 | 7792 | 1 | 40 | 1320 | 1321 | 0 | (0,10) | 8198 | 1281 | 24 | 11110000 |
11 | 7760 | 1 | 28 | 1332 | 0 | 0 | (0,11) | 6 | 2305 | 24 | 10000000 |
12 | 7728 | 1 | 28 | 1332 | 0 | 0 | (0,12) | 6 | 2305 | 24 | 10000000 |
13 | 7696 | 1 | 28 | 1332 | 0 | 0 | (0,13) | 6 | 2305 | 24 | 10000000 |
14 | 7664 | 1 | 28 | 1332 | 0 | 0 | (0,14) | 6 | 2305 | 24 | 10000000 |
15 | 7632 | 1 | 28 | 1332 | 0 | 0 | (0,15) | 6 | 2305 | 24 | 10000000 |
16 | 7600 | 1 | 28 | 1332 | 0 | 0 | (0,16) | 6 | 2305 | 24 | 10000000 |
17 | 7552 | 1 | 48 | 1333 | 0 | 0 | (0,17) | 6 | 2304 | 24 | |
(17 rows)
postgres=# \q
wln@iZ232ngsvp8Z:~> hexdump pg95/data/base/12974/41017
0000000 0000 0000 ff20 12d2 0000 0000 005c 1d80
0000010 2000 2004 0529 0000 9fd8 0050 9fb0 0050
0000020 9f88 0050 9f60 0050 9f38 0050 9f10 0050
0000030 9ee8 0050 9ec0 0050 9e98 0050 9e70 0050
0000040 9e50 0038 9e30 0038 9e10 0038 9df0 0038
0000050 9dd0 0038 9db0 0038 9d80 0060 0000 0000
0000060 0000 0000 0000 0000 0000 0000 0000 0000
*
0001d80 0535 0000 0000 0000 0000 0000 0000 0000
0001d90 0011 0006 0900 0018 000b 0000 000c 0000
0001da0 000d 0000 000e 0000 000f 0000 0010 0000
0001db0 0534 0000 0000 0000 0000 0000 0000 0000
0001dc0 0010 0006 0901 0118 0010 0000 0000 0000
0001dd0 0534 0000 0000 0000 0000 0000 0000 0000
0001de0 000f 0006 0901 0118 000f 0000 0000 0000
0001df0 0534 0000 0000 0000 0000 0000 0000 0000
0001e00 000e 0006 0901 0118 000e 0000 0000 0000
0001e10 0534 0000 0000 0000 0000 0000 0000 0000
0001e20 000d 0006 0901 0118 000d 0000 0000 0000
0001e30 0534 0000 0000 0000 0000 0000 0000 0000
0001e40 000c 0006 0901 0118 000c 0000 0000 0000
0001e50 0534 0000 0000 0000 0000 0000 0000 0000
0001e60 000b 0006 0901 0118 000b 0000 0000 0000
0001e70 0528 0000 0529 0000 0000 0000 0000 0000
0001e80 000a 2006 0501 0f18 000a 0000 0002 0000
0001e90 0003 0000 0004 0000 0528 0000 0000 0000
0001ea0 0000 0000 0000 0000 0009 0006 0901 0f18
0001eb0 0009 0000 0002 0000 0003 0000 0004 0000
0001ec0 0528 0000 0000 0000 0000 0000 0000 0000
0001ed0 0008 0006 0901 0f18 0008 0000 0002 0000
0001ee0 0003 0000 0004 0000 0528 0000 0000 0000
0001ef0 0000 0000 0000 0000 0007 0006 0901 0f18
0001f00 0007 0000 0002 0000 0003 0000 0004 0000
0001f10 0528 0000 0000 0000 0000 0000 0000 0000
0001f20 0006 0006 0901 0f18 0006 0000 0002 0000
0001f30 0003 0000 0004 0000 0528 0000 0000 0000
0001f40 0000 0000 0000 0000 0005 0006 0901 0f18
0001f50 0005 0000 0002 0000 0003 0000 0004 0000
0001f60 0528 0000 0000 0000 0000 0000 0000 0000
0001f70 0004 0006 0901 0f18 0004 0000 0002 0000
0001f80 0003 0000 0004 0000 0528 0000 0000 0000
0001f90 0000 0000 0000 0000 0003 0006 0901 0f18
0001fa0 0003 0000 0002 0000 0003 0000 0004 0000
0001fb0 0528 0000 0000 0000 0000 0000 0000 0000
0001fc0 0002 0006 0901 0f18 0002 0000 0002 0000
0001fd0 0003 0000 0004 0000 0528 0000 0000 0000
0001fe0 0000 0000 0000 0000 0001 0006 0901 0f18
0001ff0 0001 0000 0002 0000 0003 0000 0004 0000
0002000
wln@iZ232ngsvp8Z:~> hexdump pg95/data/base/12974/41017 -d
0000000 00000 00000 65312 04818 00000 00000 00092 07552
0000010 08192 08196 01321 00000 40920 00080 40880 00080
0000020 40840 00080 40800 00080 40760 00080 40720 00080
0000030 40680 00080 40640 00080 40600 00080 40560 00080
0000040 40528 00056 40496 00056 40464 00056 40432 00056
0000050 40400 00056 40368 00056 40320 00096 00000 00000
0000060 00000 00000 00000 00000 00000 00000 00000 00000
*
0001d80 01333 00000 00000 00000 00000 00000 00000 00000
0001d90 00017 00006 02304 00024 00011 00000 00012 00000
0001da0 00013 00000 00014 00000 00015 00000 00016 00000
0001db0 01332 00000 00000 00000 00000 00000 00000 00000
0001dc0 00016 00006 02305 00280 00016 00000 00000 00000
0001dd0 01332 00000 00000 00000 00000 00000 00000 00000
0001de0 00015 00006 02305 00280 00015 00000 00000 00000
0001df0 01332 00000 00000 00000 00000 00000 00000 00000
0001e00 00014 00006 02305 00280 00014 00000 00000 00000
0001e10 01332 00000 00000 00000 00000 00000 00000 00000
0001e20 00013 00006 02305 00280 00013 00000 00000 00000
0001e30 01332 00000 00000 00000 00000 00000 00000 00000
0001e40 00012 00006 02305 00280 00012 00000 00000 00000
0001e50 01332 00000 00000 00000 00000 00000 00000 00000
0001e60 00011 00006 02305 00280 00011 00000 00000 00000
0001e70 01320 00000 01321 00000 00000 00000 00000 00000
0001e80 00010 08198 01281 03864 00010 00000 00002 00000
0001e90 00003 00000 00004 00000 01320 00000 00000 00000
0001ea0 00000 00000 00000 00000 00009 00006 02305 03864
0001eb0 00009 00000 00002 00000 00003 00000 00004 00000
0001ec0 01320 00000 00000 00000 00000 00000 00000 00000
0001ed0 00008 00006 02305 03864 00008 00000 00002 00000
0001ee0 00003 00000 00004 00000 01320 00000 00000 00000
0001ef0 00000 00000 00000 00000 00007 00006 02305 03864
0001f00 00007 00000 00002 00000 00003 00000 00004 00000
0001f10 01320 00000 00000 00000 00000 00000 00000 00000
0001f20 00006 00006 02305 03864 00006 00000 00002 00000
0001f30 00003 00000 00004 00000 01320 00000 00000 00000
0001f40 00000 00000 00000 00000 00005 00006 02305 03864
0001f50 00005 00000 00002 00000 00003 00000 00004 00000
0001f60 01320 00000 00000 00000 00000 00000 00000 00000
0001f70 00004 00006 02305 03864 00004 00000 00002 00000
0001f80 00003 00000 00004 00000 01320 00000 00000 00000
0001f90 00000 00000 00000 00000 00003 00006 02305 03864
0001fa0 00003 00000 00002 00000 00003 00000 00004 00000
0001fb0 01320 00000 00000 00000 00000 00000 00000 00000
0001fc0 00002 00006 02305 03864 00002 00000 00002 00000
0001fd0 00003 00000 00004 00000 01320 00000 00000 00000
0001fe0 00000 00000 00000 00000 00001 00006 02305 03864
0001ff0 00001 00000 00002 00000 00003 00000 00004 00000
0002000
可以看出,元组头长度均为24(xmin+xmax+cmin+cmax+ctid+t_infomask2+t_infomask+t_bits+t_hoff),
元组中数据长度lp_len 为48,40,28。可以看出,有5列为空时长度最短28(24+4),无空列则为24+486=48。
//代码、
//HeapTupleHeaderData.c
#include <stdio.h>
#include <fcntl.h>
#include<stdlib.h>
#include<string.h>
#ifndef HAVE_UINT8
typedef unsigned char uint8; /* == 8 bits */
typedef unsigned short uint16; /* == 16 bits */
typedef unsigned int uint32; /* == 32 bits */
typedef uint8 bits8; /* >= 8 bits */
typedef uint16 bits16; /* >= 16 bits */
typedef uint32 bits32;
typedef signed int int32; /* >= 32 bits */
#endif /* not HAVE_UINT8 */
typedef uint32 TransactionId;
typedef uint32 CommandId;
typedef uint16 OffsetNumber;
typedef unsigned int Oid;
typedef struct DatumTupleFields
{
int32 datum_len_; /* varlena header (do not touch directly!) */
int32 datum_typmod; /* -1, or identifier of a record type */
Oid datum_typeid; /* composite type OID, or RECORDOID */
/*
* Note: field ordering is chosen with thought that Oid might someday
* widen to 64 bits.
*/
}DatumTupleFields;
/*
* BlockId:
*
* this is a storage type for BlockNumber. in other words, this type
* is used for on-disk structures (e.g., in HeapTupleData) whereas
* BlockNumber is the type on which calculations are performed (e.g.,
* in access method code).
*
* there doesn't appear to be any reason to have separate types except
* for the fact that BlockIds can be SHORTALIGN'd (and therefore any
* structures that contains them, such as ItemPointerData, can also be
* SHORTALIGN'd). this is an important consideration for reducing the
* space requirements of the line pointer (ItemIdData) array on each
* page and the header of each heap or index tuple, so it doesn't seem
* wise to change this without good reason.
*/
typedef struct BlockIdData
{
uint16 bi_hi;
uint16 bi_lo;
} BlockIdData;
/*
* ItemPointer:
*
* This is a pointer to an item within a disk page of a known file
* (for example, a cross-link from an index to its parent table).
* blkid tells us which block, posid tells us which entry in the linp
* (ItemIdData) array we want.
*
* Note: because there is an item pointer in each tuple header and index
* tuple header on disk, it's very important not to waste space with
* structure padding bytes. The struct is designed to be six bytes long
* (it contains three int16 fields) but a few compilers will pad it to
* eight bytes unless coerced. We apply appropriate persuasion where
* possible, and to cope with unpersuadable compilers, we try to use
* "SizeOfIptrData" rather than "sizeof(ItemPointerData)" when computing
* on-disk sizes.
*/
typedef struct ItemPointerData
{
BlockIdData ip_blkid;
OffsetNumber ip_posid;
}ItemPointerData;
/*
* Heap tuple header. To avoid wasting space, the fields should be
* laid out in such a way as to avoid structure padding.
*
* Datums of composite types (row types) share the same general structure
* as on-disk tuples, so that the same routines can be used to build and
* examine them. However the requirements are slightly different: a Datum
* does not need any transaction visibility information, and it does need
* a length word and some embedded type information. We can achieve this
* by overlaying the xmin/cmin/xmax/cmax/xvac fields of a heap tuple
* with the fields needed in the Datum case. Typically, all tuples built
* in-memory will be initialized with the Datum fields; but when a tuple is
* about to be inserted in a table, the transaction fields will be filled,
* overwriting the datum fields.
*
* The overall structure of a heap tuple looks like:
* fixed fields (HeapTupleHeaderData struct)
* nulls bitmap (if HEAP_HASNULL is set in t_infomask)
* alignment padding (as needed to make user data MAXALIGN'd)
* object ID (if HEAP_HASOID is set in t_infomask)
* user data fields
*
* We store five "virtual" fields Xmin, Cmin, Xmax, Cmax, and Xvac in three
* physical fields. Xmin and Xmax are always really stored, but Cmin, Cmax
* and Xvac share a field. This works because we know that Cmin and Cmax
* are only interesting for the lifetime of the inserting and deleting
* transaction respectively. If a tuple is inserted and deleted in the same
* transaction, we store a "combo" command id that can be mapped to the real
* cmin and cmax, but only by use of local state within the originating
* backend. See combocid.c for more details. Meanwhile, Xvac is only set by
* old-style VACUUM FULL, which does not have any command sub-structure and so
* does not need either Cmin or Cmax. (This requires that old-style VACUUM
* FULL never try to move a tuple whose Cmin or Cmax is still interesting,
* ie, an insert-in-progress or delete-in-progress tuple.)
*
* A word about t_ctid: whenever a new tuple is stored on disk, its t_ctid
* is initialized with its own TID (location). If the tuple is ever updated,
* its t_ctid is changed to point to the replacement version of the tuple.
* Thus, a tuple is the latest version of its row iff XMAX is invalid or
* t_ctid points to itself (in which case, if XMAX is valid, the tuple is
* either locked or deleted). One can follow the chain of t_ctid links
* to find the newest version of the row. Beware however that VACUUM might
* erase the pointed-to (newer) tuple before erasing the pointing (older)
* tuple. Hence, when following a t_ctid link, it is necessary to check
* to see if the referenced slot is empty or contains an unrelated tuple.
* Check that the referenced tuple has XMIN equal to the referencing tuple's
* XMAX to verify that it is actually the descendant version and not an
* unrelated tuple stored into a slot recently freed by VACUUM. If either
* check fails, one may assume that there is no live descendant version.
*
* t_ctid is sometimes used to store a speculative insertion token, instead
* of a real TID. A speculative token is set on a tuple that's being
* inserted, until the inserter is sure that it wants to go ahead with the
* insertion. Hence a token should only be seen on a tuple with an XMAX
* that's still in-progress, or invalid/aborted. The token is replaced with
* the tuple's real TID when the insertion is confirmed. One should never
* see a speculative insertion token while following a chain of t_ctid links,
* because they are not used on updates, only insertions.
*
* Following the fixed header fields, the nulls bitmap is stored (beginning
* at t_bits). The bitmap is *not* stored if t_infomask shows that there
* are no nulls in the tuple. If an OID field is present (as indicated by
* t_infomask), then it is stored just before the user data, which begins at
* the offset shown by t_hoff. Note that t_hoff must be a multiple of
* MAXALIGN.
*/
typedef struct HeapTupleFields
{
TransactionId t_xmin; /* inserting xact ID */
TransactionId t_xmax; /* deleting or locking xact ID */
union
{
CommandId t_cid; /* inserting or deleting command ID, or both */
TransactionId t_xvac; /* old-style VACUUM FULL xact ID */
} t_field3;
}HeapTupleFields ;
//add by wln
#define FLEXIBLE_ARRAY_MEMBER 1
struct HeapTupleHeaderData
{
union
{
HeapTupleFields t_heap;
DatumTupleFields t_datum;
} t_choice;
ItemPointerData t_ctid; /* current TID of this or newer tuple (or a
* speculative insertion token) */
/* Fields below here must match MinimalTupleData! */
uint16 t_infomask2; /* number of attributes + various flags */
uint16 t_infomask; /* various flag bits, see below */
uint8 t_hoff; /* sizeof header incl. bitmap, padding */
/* ^ - 23 bytes - ^ */
bits8 t_bits[FLEXIBLE_ARRAY_MEMBER]; /* bitmap of NULLs */
/* MORE DATA FOLLOWS AT END OF STRUCT */
};
/*
* this macro used to print variable
*/
#define print(n) printf(#n" = %d\n",n)
int main(int argc,char *argv[])
{
if(argc<2 || (argc>=2 && access(argv[1], F_OK)))
{
printf("file:%s doesnot exist.\n",argv[1]);
exit(1);
}
char filename[1024];
strncpy(filename,argv[1],strlen(argv[1])+1); //must +1
printf("filename:%s,%d\n",filename,strlen(filename));
int fd;
if((fd=open(filename,O_RDONLY))==-1)
{
printf("%m,%s,line:%d\n",__FILE__,__LINE__);
exit(1);
}
struct HeapTupleHeaderData HeapTupleHeaderDataEle;
lseek(fd,7872,SEEK_SET);
if(read(fd,&HeapTupleHeaderDataEle,sizeof(HeapTupleHeaderDataEle))==-1)
{
printf("%m,%s,line:%d\n",__FILE__,__LINE__);
exit(1);
}
printf("sizeof(HeapTupleHeaderData)=%d\n",sizeof(HeapTupleHeaderDataEle));
print(HeapTupleHeaderDataEle.t_choice.t_heap.t_xmin);
print(HeapTupleHeaderDataEle.t_choice.t_heap.t_xmax);
print(HeapTupleHeaderDataEle.t_ctid.ip_blkid);
print(HeapTupleHeaderDataEle.t_ctid.ip_posid);
print(HeapTupleHeaderDataEle.t_infomask2);
print(HeapTupleHeaderDataEle.t_infomask);
print(HeapTupleHeaderDataEle.t_hoff);
print(HeapTupleHeaderDataEle.t_bits[0]);
close(fd);
}
//HeapTupleHeaderData.c
测试:
wln@iZ232ngsvp8Z:~/pg95> ./HeapTupleHeaderData data/base/12974/41021
filename:data/base/12974/41021,21
sizeof(HeapTupleHeaderData)=24
HeapTupleHeaderDataEle.t_choice.t_heap.t_xmin = 1329
HeapTupleHeaderDataEle.t_choice.t_heap.t_xmax = 0
HeapTupleHeaderDataEle.t_ctid.ip_blkid = 0
HeapTupleHeaderDataEle.t_ctid.ip_posid = 10
HeapTupleHeaderDataEle.t_infomask2 = 1
HeapTupleHeaderDataEle.t_infomask = 2304
HeapTupleHeaderDataEle.t_hoff = 24
HeapTupleHeaderDataEle.t_bits[0] = 0
wln@iZ232ngsvp8Z:~/pg95> psql
psql (9.5beta1)
Type "help" for help.
postgres=# select * from heap_page_items(get_raw_page('t1', 'main', 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
----+--------+----------+--------+--------+--------+----------+--------+-------------+------------+--------+--------+-------
1 | 8160 | 1 | 28 | 1326 | 0 | 0 | (0,1) | 1 | 2304 | 24 | |
2 | 8128 | 1 | 28 | 1326 | 1326 | 0 | (0,2) | 8193 | 1312 | 24 | |
3 | 8096 | 1 | 28 | 1327 | 0 | 0 | (0,3) | 1 | 2304 | 24 | |
4 | 8064 | 1 | 28 | 1327 | 0 | 1 | (0,4) | 1 | 2304 | 24 | |
5 | 8032 | 1 | 28 | 1328 | 0 | 0 | (0,5) | 1 | 2304 | 24 | |
6 | 8000 | 1 | 28 | 1328 | 0 | 1 | (0,6) | 1 | 2304 | 24 | |
7 | 7968 | 1 | 28 | 1329 | 0 | 0 | (0,7) | 1 | 2304 | 24 | |
8 | 7936 | 1 | 28 | 1329 | 0 | 1 | (0,8) | 1 | 2304 | 24 | |
9 | 7904 | 1 | 28 | 1329 | 0 | 2 | (0,9) | 1 | 2304 | 24 | |
10 | 7872 | 1 | 28 | 1329 | 0 | 3 | (0,10) | 1 | 2304 | 24 | |
(10 rows)
可以看出,和用插件查看的是一致的。lseek 位置是可以通过hexdump查看具体行位置,也可以通过PageHeaderData.c
函数取得各个tuple对应的行在page中的offset。