1 <!-- doc/src/sgml/pageinspect.sgml -->
3 <sect1 id="pageinspect" xreflabel="pageinspect">
4 <title>pageinspect</title>
6 <indexterm zone="pageinspect">
7 <primary>pageinspect</primary>
11 The <filename>pageinspect</> module provides functions that allow you to
12 inspect the contents of database pages at a low level, which is useful for
13 debugging purposes. All of these functions may be used only by superusers.
17 <title>Functions</title>
22 <function>get_raw_page(relname text, fork text, blkno int) returns bytea</function>
24 <primary>get_raw_page</primary>
30 <function>get_raw_page</function> reads the specified block of the named
31 relation and returns a copy as a <type>bytea</> value. This allows a
32 single time-consistent copy of the block to be obtained.
33 <replaceable>fork</replaceable> should be <literal>'main'</literal> for
34 the main data fork, <literal>'fsm'</literal> for the free space map,
35 <literal>'vm'</literal> for the visibility map, or <literal>'init'</literal>
36 for the initialization fork.
43 <function>get_raw_page(relname text, blkno int) returns bytea</function>
48 A shorthand version of <function>get_raw_page</function>, for reading
49 from the main fork. Equivalent to
50 <literal>get_raw_page(relname, 'main', blkno)</literal>
57 <function>page_header(page bytea) returns record</function>
59 <primary>page_header</primary>
65 <function>page_header</function> shows fields that are common to all
66 <productname>PostgreSQL</> heap and index pages.
70 A page image obtained with <function>get_raw_page</function> should be
71 passed as argument. For example:
73 test=# SELECT * FROM page_header(get_raw_page('pg_class', 0));
74 lsn | checksum | flags | lower | upper | special | pagesize | version | prune_xid
75 -----------+----------+--------+-------+-------+---------+----------+---------+-----------
76 0/24A1B50 | 1 | 1 | 232 | 368 | 8192 | 8192 | 4 | 0
78 The returned columns correspond to the fields in the
79 <structname>PageHeaderData</> struct.
80 See <filename>src/include/storage/bufpage.h</> for details.
87 <function>heap_page_items(page bytea) returns setof record</function>
89 <primary>heap_page_items</primary>
95 <function>heap_page_items</function> shows all line pointers on a heap
96 page. For those line pointers that are in use, tuple headers as well
97 as tuple raw data are also shown. All tuples are shown, whether or not
98 the tuples were visible to an MVCC snapshot at the time the raw page
102 A heap page image obtained with <function>get_raw_page</function> should
103 be passed as argument. For example:
105 test=# SELECT * FROM heap_page_items(get_raw_page('pg_class', 0));
107 See <filename>src/include/storage/itemid.h</> and
108 <filename>src/include/access/htup_details.h</> for explanations of the fields
116 <function>tuple_data_split(rel_oid, t_data bytea, t_infomask integer, t_infomask2 integer, t_bits text [, do_detoast bool]) returns bytea[]</function>
118 <primary>tuple_data_split</primary>
123 <function>tuple_data_split</function> splits tuple data into attributes
124 in the same way as backend internals.
126 test=# SELECT tuple_data_split('pg_class'::regclass, t_data, t_infomask, t_infomask2, t_bits) FROM heap_page_items(get_raw_page('pg_class', 0));
128 This function should be called with the same arguments as the return
129 attributes of <function>heap_page_items</function>.
132 If <parameter>do_detoast</parameter> is <literal>true</literal>,
133 attribute that will be detoasted as needed. Default value is
134 <literal>false</literal>.
141 <function>heap_page_item_attrs(rel_oid, t_data bytea, [, do_detoast bool]) returns bytea[]</function>
143 <primary>heap_page_item_attrs</primary>
148 <function>heap_page_item_attrs</function> is equivalent to
149 <function>heap_page_items</function> except that it returns
150 tuple raw data as an array of attributes that can optionally
151 be detoasted by <parameter>do_detoast</parameter> which is
152 <literal>false</literal> by default.
155 A heap page image obtained with <function>get_raw_page</function> should
156 be passed as argument. For example:
158 test=# SELECT * FROM heap_page_item_attrs(get_raw_page('pg_class', 0), 'pg_class'::regclass);
166 <function>bt_metap(relname text) returns record</function>
168 <primary>bt_metap</primary>
174 <function>bt_metap</function> returns information about a B-tree
175 index's metapage. For example:
177 test=# SELECT * FROM bt_metap('pg_cast_oid_index');
192 <function>bt_page_stats(relname text, blkno int) returns record</function>
194 <primary>bt_page_stats</primary>
200 <function>bt_page_stats</function> returns summary information about
201 single pages of B-tree indexes. For example:
203 test=# SELECT * FROM bt_page_stats('pg_cast_oid_index', 1);
223 <function>bt_page_items(relname text, blkno int) returns setof record</function>
225 <primary>bt_page_items</primary>
231 <function>bt_page_items</function> returns detailed information about
232 all of the items on a B-tree index page. For example:
234 test=# SELECT * FROM bt_page_items('pg_cast_oid_index', 1);
235 itemoffset | ctid | itemlen | nulls | vars | data
236 ------------+---------+---------+-------+------+-------------
237 1 | (0,1) | 12 | f | f | 23 27 00 00
238 2 | (0,2) | 12 | f | f | 24 27 00 00
239 3 | (0,3) | 12 | f | f | 25 27 00 00
240 4 | (0,4) | 12 | f | f | 26 27 00 00
241 5 | (0,5) | 12 | f | f | 27 27 00 00
242 6 | (0,6) | 12 | f | f | 28 27 00 00
243 7 | (0,7) | 12 | f | f | 29 27 00 00
244 8 | (0,8) | 12 | f | f | 2a 27 00 00
246 In a B-tree leaf page, <structfield>ctid</> points to a heap tuple.
247 In an internal page, the block number part of <structfield>ctid</>
248 points to another page in the index itself, while the offset part
249 (the second number) is ignored and is usually 1.
252 Note that the first item on any non-rightmost page (any page with
253 a non-zero value in the <structfield>btpo_next</> field) is the
254 page's <quote>high key</quote>, meaning its <structfield>data</>
255 serves as an upper bound on all items appearing on the page, while
256 its <structfield>ctid</> field is meaningless. Also, on non-leaf
257 pages, the first real data item (the first item that is not a high
258 key) is a <quote>minus infinity</quote> item, with no actual value
259 in its <structfield>data</> field. Such an item does have a valid
260 downlink in its <structfield>ctid</> field, however.
267 <function>brin_page_type(page bytea) returns text</function>
269 <primary>brin_page_type</primary>
275 <function>brin_page_type</function> returns the page type of the given
276 <acronym>BRIN</acronym> index page, or throws an error if the page is
277 not a valid <acronym>BRIN</acronym> page. For example:
279 test=# SELECT brin_page_type(get_raw_page('brinidx', 0));
290 <function>brin_metapage_info(page bytea) returns record</function>
292 <primary>brin_metapage_info</primary>
298 <function>brin_metapage_info</function> returns assorted information
299 about a <acronym>BRIN</acronym> index metapage. For example:
301 test=# SELECT * FROM brin_metapage_info(get_raw_page('brinidx', 0));
302 magic | version | pagesperrange | lastrevmappage
303 ------------+---------+---------------+----------------
304 0xA8109CFA | 1 | 4 | 2
312 <function>brin_revmap_data(page bytea) returns setof tid</function>
314 <primary>brin_revmap_data</primary>
320 <function>brin_revmap_data</function> returns the list of tuple
321 identifiers in a <acronym>BRIN</acronym> index range map page.
324 test=# SELECT * FROM brin_revmap_data(get_raw_page('brinidx', 2)) limit 5;
339 <function>brin_page_items(page bytea, index oid) returns setof record</function>
341 <primary>brin_page_items</primary>
347 <function>brin_page_items</function> returns the data stored in the
348 <acronym>BRIN</acronym> data page. For example:
350 test=# SELECT * FROM brin_page_items(get_raw_page('brinidx', 5),
352 ORDER BY blknum, attnum LIMIT 6;
353 itemoffset | blknum | attnum | allnulls | hasnulls | placeholder | value
354 ------------+--------+--------+----------+----------+-------------+--------------
355 137 | 0 | 1 | t | f | f |
356 137 | 0 | 2 | f | f | f | {1 .. 88}
357 138 | 4 | 1 | t | f | f |
358 138 | 4 | 2 | f | f | f | {89 .. 176}
359 139 | 8 | 1 | t | f | f |
360 139 | 8 | 2 | f | f | f | {177 .. 264}
362 The returned columns correspond to the fields in the
363 <structname>BrinMemTuple</> and <structname>BrinValues</> structs.
364 See <filename>src/include/access/brin_tuple.h</> for details.
371 <function>gin_metapage_info(page bytea) returns record</function>
373 <primary>gin_metapage_info</primary>
379 <function>gin_metapage_info</function> returns information about
380 a <acronym>GIN</acronym> index metapage. For example:
382 test=# SELECT * FROM gin_metapage_info(get_raw_page('gin_index', 0));
383 -[ RECORD 1 ]----+-----------
384 pending_head | 4294967295
385 pending_tail | 4294967295
401 <function>gin_page_opaque_info(page bytea) returns record</function>
403 <primary>gin_page_opaque_info</primary>
409 <function>gin_page_opaque_info</function> returns information about
410 a <acronym>GIN</acronym> index opaque area, like the page type.
413 test=# SELECT * FROM gin_page_opaque_info(get_raw_page('gin_index', 2));
414 rightlink | maxoff | flags
415 -----------+--------+------------------------
416 5 | 0 | {data,leaf,compressed}
425 <function>gin_leafpage_items(page bytea) returns setof record</function>
427 <primary>gin_leafpage_items</primary>
433 <function>gin_leafpage_items</function> returns information about
434 the data stored in a <acronym>GIN</acronym> leaf page. For example:
436 test=# SELECT first_tid, nbytes, tids[0:5] as some_tids
437 FROM gin_leafpage_items(get_raw_page('gin_test_idx', 2));
438 first_tid | nbytes | some_tids
439 -----------+--------+----------------------------------------------------------
440 (8,41) | 244 | {"(8,41)","(8,43)","(8,44)","(8,45)","(8,46)"}
441 (10,45) | 248 | {"(10,45)","(10,46)","(10,47)","(10,48)","(10,49)"}
442 (12,52) | 248 | {"(12,52)","(12,53)","(12,54)","(12,55)","(12,56)"}
443 (14,59) | 320 | {"(14,59)","(14,60)","(14,61)","(14,62)","(14,63)"}
444 (167,16) | 376 | {"(167,16)","(167,17)","(167,18)","(167,19)","(167,20)"}
445 (170,30) | 376 | {"(170,30)","(170,31)","(170,32)","(170,33)","(170,34)"}
446 (173,44) | 197 | {"(173,44)","(173,45)","(173,46)","(173,47)","(173,48)"}
455 <function>fsm_page_contents(page bytea) returns text</function>
457 <primary>fsm_page_contents</primary>
463 <function>fsm_page_contents</function> shows the internal node structure
464 of a FSM page. The output is a multiline string, with one line per
465 node in the binary tree within the page. Only those nodes that are not
466 zero are printed. The so-called "next" pointer, which points to the
467 next slot to be returned from the page, is also printed.
470 See <filename>src/backend/storage/freespace/README</> for more
471 information on the structure of an FSM page.