3 <sect1 id=
"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>
27 <function>get_raw_page
</function> reads the specified block of the named
28 table and returns a copy as a
<type>bytea<
/> value. This allows a
29 single time-consistent copy of the block to be obtained.
30 <literal>fork
</literal> should be
<literal>'main'
</literal> for the main
31 data fork, or
<literal>'fsm'
</literal> for the FSM.
38 <function>get_raw_page(relname text, blkno int) returns bytea
</function>
43 A shorthand of above, for reading from the main fork. Equal to
44 <literal>get_raw_page(relname,
0, blkno)
</literal>
51 <function>page_header(page bytea) returns record
</function>
56 <function>page_header
</function> shows fields that are common to all
57 <productname>PostgreSQL<
/> heap and index pages.
61 A page image obtained with
<function>get_raw_page
</function> should be
62 passed as argument. For example:
65 test=# SELECT * FROM page_header(get_raw_page('pg_class',
0));
66 lsn | tli | flags | lower | upper | special | pagesize | version | prune_xid
67 -----------+-----+-------+-------+-------+---------+----------+---------+-----------
68 0/
24A1B50 |
1 |
1 |
232 |
368 |
8192 |
8192 |
4 |
0
72 The returned columns correspond to the fields in the
73 <structname>PageHeaderData<
/> struct.
74 See
<filename>src/include/storage/bufpage.h<
/> for details.
81 <function>heap_page_items(page bytea) returns setof record
</function>
86 <function>heap_page_items
</function> shows all line pointers on a heap
87 page. For those line pointers that are in use, tuple headers are also
88 shown. All tuples are shown, whether or not the tuples were visible to
89 an MVCC snapshot at the time the raw page was copied.
92 A heap page image obtained with
<function>get_raw_page
</function> should
93 be passed as argument. For example:
96 test=# SELECT * FROM heap_page_items(get_raw_page('pg_class',
0));
99 See
<filename>src/include/storage/itemid.h<
/> and
100 <filename>src/include/access/htup.h<
/> for explanations of the fields
108 <function>bt_metap(relname text) returns record
</function>
113 <function>bt_metap
</function> returns information about a btree
114 index's metapage. For example:
117 test=# SELECT * FROM bt_metap('pg_cast_oid_index');
131 <function>bt_page_stats(relname text, blkno int) returns record
</function>
136 <function>bt_page_stats
</function> returns summary information about
137 single pages of btree indexes. For example:
140 test=# SELECT * FROM bt_page_stats('pg_cast_oid_index',
1);
159 <function>bt_page_items(relname text, blkno int) returns setof record
</function>
164 <function>bt_page_items
</function> returns detailed information about
165 all of the items on a btree index page. For example:
168 test=# SELECT * FROM bt_page_items('pg_cast_oid_index',
1);
169 itemoffset | ctid | itemlen | nulls | vars | data
170 ------------+---------+---------+-------+------+-------------
171 1 | (
0,
1) |
12 | f | f |
23 27 00 00
172 2 | (
0,
2) |
12 | f | f |
24 27 00 00
173 3 | (
0,
3) |
12 | f | f |
25 27 00 00
174 4 | (
0,
4) |
12 | f | f |
26 27 00 00
175 5 | (
0,
5) |
12 | f | f |
27 27 00 00
176 6 | (
0,
6) |
12 | f | f |
28 27 00 00
177 7 | (
0,
7) |
12 | f | f |
29 27 00 00
178 8 | (
0,
8) |
12 | f | f |
2a
27 00 00
185 <function>fsm_page_contents(page bytea) returns text
</function>
190 <function>fsm_page_contents
</function> shows the internal node structure
191 of a FSM page. The output is a multi-line string, with one line per
192 node in the binary tree within the page. Only those nodes that are not
193 zero are printed. The so-called
"next" pointer, which points to the
194 next slot to be returned from the page, is also printed.
197 See
<filename>src/backend/storage/freespace/README<
/> for more
198 information on the structure of an FSM page.