summaryrefslogtreecommitdiff
path: root/doc/src/sgml/pageinspect.sgml
blob: 191fb156c13bb2b7ec9b7b119860f48c1c20e904 (plain)
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
<!-- doc/src/sgml/pageinspect.sgml -->

<sect1 id="pageinspect" xreflabel="pageinspect">
 <title>pageinspect</title>

 <indexterm zone="pageinspect">
  <primary>pageinspect</primary>
 </indexterm>

 <para>
  The <filename>pageinspect</> module provides functions that allow you to
  inspect the contents of database pages at a low level, which is useful for
  debugging purposes.  All of these functions may be used only by superusers.
 </para>

 <sect2>
  <title>Functions</title>

  <variablelist>
   <varlistentry>
    <term>
     <function>get_raw_page(relname text, fork text, blkno int) returns bytea</function>
     <indexterm>
      <primary>get_raw_page</primary>
     </indexterm>
    </term>

    <listitem>
     <para>
      <function>get_raw_page</function> reads the specified block of the named
      relation and returns a copy as a <type>bytea</> value.  This allows a
      single time-consistent copy of the block to be obtained.
      <replaceable>fork</replaceable> should be <literal>'main'</literal> for
      the main data fork, <literal>'fsm'</literal> for the free space map,
      <literal>'vm'</literal> for the visibility map, or <literal>'init'</literal>
      for the initialization fork.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term>
     <function>get_raw_page(relname text, blkno int) returns bytea</function>
    </term>

    <listitem>
     <para>
      A shorthand version of <function>get_raw_page</function>, for reading
      from the main fork.  Equivalent to
      <literal>get_raw_page(relname, 'main', blkno)</literal>
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term>
     <function>page_header(page bytea) returns record</function>
     <indexterm>
      <primary>page_header</primary>
     </indexterm>
    </term>

    <listitem>
     <para>
      <function>page_header</function> shows fields that are common to all
      <productname>PostgreSQL</> heap and index pages.
     </para>

     <para>
      A page image obtained with <function>get_raw_page</function> should be
      passed as argument.  For example:
<screen>
test=# SELECT * FROM page_header(get_raw_page('pg_class', 0));
    lsn    | checksum | flags  | lower | upper | special | pagesize | version | prune_xid
-----------+----------+--------+-------+-------+---------+----------+---------+-----------
 0/24A1B50 |        1 |      1 |   232 |   368 |    8192 |     8192 |       4 |         0
</screen>
      The returned columns correspond to the fields in the
      <structname>PageHeaderData</> struct.
      See <filename>src/include/storage/bufpage.h</> for details.
    </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term>
     <function>heap_page_items(page bytea) returns setof record</function>
     <indexterm>
      <primary>heap_page_items</primary>
     </indexterm>
    </term>

    <listitem>
     <para>
      <function>heap_page_items</function> shows all line pointers on a heap
      page.  For those line pointers that are in use, tuple headers are also
      shown. All tuples are shown, whether or not the tuples were visible to
      an MVCC snapshot at the time the raw page was copied.
     </para>
     <para>
      A heap page image obtained with <function>get_raw_page</function> should
      be passed as argument.  For example:
<screen>
test=# SELECT * FROM heap_page_items(get_raw_page('pg_class', 0));
</screen>
      See <filename>src/include/storage/itemid.h</> and
      <filename>src/include/access/htup_details.h</> for explanations of the fields
      returned.
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term>
     <function>bt_metap(relname text) returns record</function>
     <indexterm>
      <primary>bt_metap</primary>
     </indexterm>
    </term>

    <listitem>
     <para>
      <function>bt_metap</function> returns information about a B-tree
      index's metapage.  For example:
<screen>
test=# SELECT * FROM bt_metap('pg_cast_oid_index');
-[ RECORD 1 ]-----
magic     | 340322
version   | 2
root      | 1
level     | 0
fastroot  | 1
fastlevel | 0
</screen>
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term>
     <function>bt_page_stats(relname text, blkno int) returns record</function>
     <indexterm>
      <primary>bt_page_stats</primary>
     </indexterm>
    </term>

    <listitem>
     <para>
      <function>bt_page_stats</function> returns summary information about
      single pages of B-tree indexes.  For example:
<screen>
test=# SELECT * FROM bt_page_stats('pg_cast_oid_index', 1);
-[ RECORD 1 ]-+-----
blkno         | 1
type          | l
live_items    | 256
dead_items    | 0
avg_item_size | 12
page_size     | 8192
free_size     | 4056
btpo_prev     | 0
btpo_next     | 0
btpo          | 0
btpo_flags    | 3
</screen>
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term>
     <function>bt_page_items(relname text, blkno int) returns setof record</function>
     <indexterm>
      <primary>bt_page_items</primary>
     </indexterm>
    </term>

    <listitem>
     <para>
      <function>bt_page_items</function> returns detailed information about
      all of the items on a B-tree index page.  For example:
<screen>
test=# SELECT * FROM bt_page_items('pg_cast_oid_index', 1);
 itemoffset |  ctid   | itemlen | nulls | vars |    data
------------+---------+---------+-------+------+-------------
          1 | (0,1)   |      12 | f     | f    | 23 27 00 00
          2 | (0,2)   |      12 | f     | f    | 24 27 00 00
          3 | (0,3)   |      12 | f     | f    | 25 27 00 00
          4 | (0,4)   |      12 | f     | f    | 26 27 00 00
          5 | (0,5)   |      12 | f     | f    | 27 27 00 00
          6 | (0,6)   |      12 | f     | f    | 28 27 00 00
          7 | (0,7)   |      12 | f     | f    | 29 27 00 00
          8 | (0,8)   |      12 | f     | f    | 2a 27 00 00
</screen>
     </para>
    </listitem>
   </varlistentry>

   <varlistentry>
    <term>
     <function>fsm_page_contents(page bytea) returns text</function>
     <indexterm>
      <primary>fsm_page_contents</primary>
     </indexterm>
    </term>

    <listitem>
     <para>
      <function>fsm_page_contents</function> shows the internal node structure
      of a FSM page. The output is a multiline string, with one line per
      node in the binary tree within the page. Only those nodes that are not
      zero are printed. The so-called "next" pointer, which points to the
      next slot to be returned from the page, is also printed.
     </para>
     <para>
      See <filename>src/backend/storage/freespace/README</> for more
      information on the structure of an FSM page.
     </para>
    </listitem>
   </varlistentry>
  </variablelist>
 </sect2>

</sect1>