3 <sect1 id=
"pgstattuple">
4 <title>pgstattuple
</title>
6 <indexterm zone=
"pgstattuple">
7 <primary>pgstattuple
</primary>
11 The
<filename>pgstattuple
</filename> module provides various functions to
12 obtain tuple-level statistics.
16 <title>Functions
</title>
21 <function>pgstattuple(text) returns record<
/>
26 <function>pgstattuple
</function> returns a relation's physical length,
27 percentage of
<quote>dead<
/> tuples, and other info. This may help users
28 to determine whether vacuum is necessary or not. The argument is the
29 target relation's name (optionally schema-qualified).
32 test=
> SELECT * FROM pgstattuple('pg_catalog.pg_proc');
33 -[ RECORD
1 ]------+-------
40 dead_tuple_percent |
0.69
44 The output columns are described in
<xref linkend=
"pgstattuple-columns">.
47 <table id=
"pgstattuple-columns">
48 <title><function>pgstattuple
</function> output columns
</title>
54 <entry>Description
</entry>
60 <entry><structfield>table_len
</structfield></entry>
61 <entry><type>bigint
</type></entry>
62 <entry>Physical relation length in bytes
</entry>
65 <entry><structfield>tuple_count
</structfield></entry>
66 <entry><type>bigint
</type></entry>
67 <entry>Number of live tuples
</entry>
70 <entry><structfield>tuple_len
</structfield></entry>
71 <entry><type>bigint
</type></entry>
72 <entry>Total length of live tuples in bytes
</entry>
75 <entry><structfield>tuple_percent
</structfield></entry>
76 <entry><type>float8
</type></entry>
77 <entry>Percentage of live tuples
</entry>
80 <entry><structfield>dead_tuple_count
</structfield></entry>
81 <entry><type>bigint
</type></entry>
82 <entry>Number of dead tuples
</entry>
85 <entry><structfield>dead_tuple_len
</structfield></entry>
86 <entry><type>bigint
</type></entry>
87 <entry>Total length of dead tuples in bytes
</entry>
90 <entry><structfield>dead_tuple_percent
</structfield></entry>
91 <entry><type>float8
</type></entry>
92 <entry>Percentage of dead tuples
</entry>
95 <entry><structfield>free_space
</structfield></entry>
96 <entry><type>bigint
</type></entry>
97 <entry>Total free space in bytes
</entry>
100 <entry><structfield>free_percent
</structfield></entry>
101 <entry><type>float8
</type></entry>
102 <entry>Percentage of free space
</entry>
110 <function>pgstattuple
</function> acquires only a read lock on the
111 relation. So the results do not reflect an instantaneous snapshot;
112 concurrent updates will affect them.
116 <function>pgstattuple
</function> judges a tuple is
<quote>dead<
/> if
117 <function>HeapTupleSatisfiesNow<
/> returns false.
124 <function>pgstattuple(oid) returns record<
/>
129 This is the same as
<function>pgstattuple(text)
</function>, except
130 that the target relation is specified by OID.
137 <function>pgstatindex(text) returns record<
/>
142 <function>pgstatindex
</function> returns a record showing information
143 about a btree index. For example:
146 test=
> SELECT * FROM pgstatindex('pg_cast_oid_index');
147 -[ RECORD
1 ]------+------
156 avg_leaf_density |
50.27
157 leaf_fragmentation |
0
161 The output columns are:
165 <title><function>pgstatindex
</function> output columns
</title>
169 <entry>Column
</entry>
171 <entry>Description
</entry>
177 <entry><structfield>version
</structfield></entry>
178 <entry><type>integer
</type></entry>
179 <entry>Btree version number
</entry>
183 <entry><structfield>tree_level
</structfield></entry>
184 <entry><type>integer
</type></entry>
185 <entry>Tree level of the root page
</entry>
189 <entry><structfield>index_size
</structfield></entry>
190 <entry><type>bigint
</type></entry>
191 <entry>Total number of pages in index
</entry>
195 <entry><structfield>root_block_no
</structfield></entry>
196 <entry><type>bigint
</type></entry>
197 <entry>Location of root block
</entry>
201 <entry><structfield>internal_pages
</structfield></entry>
202 <entry><type>bigint
</type></entry>
203 <entry>Number of
<quote>internal<
/> (upper-level) pages
</entry>
207 <entry><structfield>leaf_pages
</structfield></entry>
208 <entry><type>bigint
</type></entry>
209 <entry>Number of leaf pages
</entry>
213 <entry><structfield>empty_pages
</structfield></entry>
214 <entry><type>bigint
</type></entry>
215 <entry>Number of empty pages
</entry>
219 <entry><structfield>deleted_pages
</structfield></entry>
220 <entry><type>bigint
</type></entry>
221 <entry>Number of deleted pages
</entry>
225 <entry><structfield>avg_leaf_density
</structfield></entry>
226 <entry><type>float8
</type></entry>
227 <entry>Average density of leaf pages
</entry>
231 <entry><structfield>leaf_fragmentation
</structfield></entry>
232 <entry><type>float8
</type></entry>
233 <entry>Leaf page fragmentation
</entry>
241 As with
<function>pgstattuple<
/>, the results are accumulated
242 page-by-page, and should not be expected to represent an
243 instantaneous snapshot of the whole index.
250 <function>pg_relpages(text) returns bigint<
/>
255 <function>pg_relpages
</function> returns the number of pages in the
264 <title>Authors
</title>
267 Tatsuo Ishii and Satoshi Nagayasu