gooderp18绿色标准版
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

199 lines
19KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>F.30. pgstattuple</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="pgstatstatements.html" title="F.29. pg_stat_statements" /><link rel="next" href="pgtrgm.html" title="F.31. pg_trgm" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">F.30. pgstattuple</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="pgstatstatements.html" title="F.29. pg_stat_statements">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="contrib.html" title="Appendix F. Additional Supplied Modules">Up</a></td><th width="60%" align="center">Appendix F. Additional Supplied Modules</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="pgtrgm.html" title="F.31. pg_trgm">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="PGSTATTUPLE"><div class="titlepage"><div><div><h2 class="title" style="clear: both">F.30. pgstattuple</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="pgstattuple.html#id-1.11.7.39.5">F.30.1. Functions</a></span></dt><dt><span class="sect2"><a href="pgstattuple.html#id-1.11.7.39.6">F.30.2. Authors</a></span></dt></dl></div><a id="id-1.11.7.39.2" class="indexterm"></a><p>
  3. The <code class="filename">pgstattuple</code> module provides various functions to
  4. obtain tuple-level statistics.
  5. </p><p>
  6. Because these functions return detailed page-level information, access is
  7. restricted by default. By default, only the
  8. role <code class="literal">pg_stat_scan_tables</code> has <code class="literal">EXECUTE</code>
  9. privilege. Superusers of course bypass this restriction. After the
  10. extension has been installed, users may issue <code class="command">GRANT</code>
  11. commands to change the privileges on the functions to allow others to
  12. execute them. However, it might be preferable to add those users to
  13. the <code class="literal">pg_stat_scan_tables</code> role instead.
  14. </p><div class="sect2" id="id-1.11.7.39.5"><div class="titlepage"><div><div><h3 class="title">F.30.1. Functions</h3></div></div></div><div class="variablelist"><dl class="variablelist"><dt><span class="term">
  15. <a id="id-1.11.7.39.5.2.1.1.1" class="indexterm"></a>
  16. <code class="function">pgstattuple(regclass) returns record</code>
  17. </span></dt><dd><p>
  18. <code class="function">pgstattuple</code> returns a relation's physical length,
  19. percentage of <span class="quote">“<span class="quote">dead</span>”</span> tuples, and other info. This may help users
  20. to determine whether vacuum is necessary or not. The argument is the
  21. target relation's name (optionally schema-qualified) or OID.
  22. For example:
  23. </p><pre class="programlisting">
  24. test=&gt; SELECT * FROM pgstattuple('pg_catalog.pg_proc');
  25. -[ RECORD 1 ]------+-------
  26. table_len | 458752
  27. tuple_count | 1470
  28. tuple_len | 438896
  29. tuple_percent | 95.67
  30. dead_tuple_count | 11
  31. dead_tuple_len | 3157
  32. dead_tuple_percent | 0.69
  33. free_space | 8932
  34. free_percent | 1.95
  35. </pre><p>
  36. The output columns are described in <a class="xref" href="pgstattuple.html#PGSTATTUPLE-COLUMNS" title="Table F.22. pgstattuple Output Columns">Table F.22</a>.
  37. </p><div class="table" id="PGSTATTUPLE-COLUMNS"><p class="title"><strong>Table F.22. <code class="function">pgstattuple</code> Output Columns</strong></p><div class="table-contents"><table class="table" summary="pgstattuple Output Columns" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">table_len</code></td><td><code class="type">bigint</code></td><td>Physical relation length in bytes</td></tr><tr><td><code class="structfield">tuple_count</code></td><td><code class="type">bigint</code></td><td>Number of live tuples</td></tr><tr><td><code class="structfield">tuple_len</code></td><td><code class="type">bigint</code></td><td>Total length of live tuples in bytes</td></tr><tr><td><code class="structfield">tuple_percent</code></td><td><code class="type">float8</code></td><td>Percentage of live tuples</td></tr><tr><td><code class="structfield">dead_tuple_count</code></td><td><code class="type">bigint</code></td><td>Number of dead tuples</td></tr><tr><td><code class="structfield">dead_tuple_len</code></td><td><code class="type">bigint</code></td><td>Total length of dead tuples in bytes</td></tr><tr><td><code class="structfield">dead_tuple_percent</code></td><td><code class="type">float8</code></td><td>Percentage of dead tuples</td></tr><tr><td><code class="structfield">free_space</code></td><td><code class="type">bigint</code></td><td>Total free space in bytes</td></tr><tr><td><code class="structfield">free_percent</code></td><td><code class="type">float8</code></td><td>Percentage of free space</td></tr></tbody></table></div></div><br class="table-break" /><div class="note"><h3 class="title">Note</h3><p>
  38. The <code class="literal">table_len</code> will always be greater than the sum
  39. of the <code class="literal">tuple_len</code>, <code class="literal">dead_tuple_len</code>
  40. and <code class="literal">free_space</code>. The difference is accounted for by
  41. fixed page overhead, the per-page table of pointers to tuples, and
  42. padding to ensure that tuples are correctly aligned.
  43. </p></div><p>
  44. <code class="function">pgstattuple</code> acquires only a read lock on the
  45. relation. So the results do not reflect an instantaneous snapshot;
  46. concurrent updates will affect them.
  47. </p><p>
  48. <code class="function">pgstattuple</code> judges a tuple is <span class="quote">“<span class="quote">dead</span>”</span> if
  49. <code class="function">HeapTupleSatisfiesDirty</code> returns false.
  50. </p></dd><dt><span class="term">
  51. <code class="function">pgstattuple(text) returns record</code>
  52. </span></dt><dd><p>
  53. This is the same as <code class="function">pgstattuple(regclass)</code>, except
  54. that the target relation is specified as TEXT. This function is kept
  55. because of backward-compatibility so far, and will be deprecated in
  56. some future release.
  57. </p></dd><dt><span class="term">
  58. <a id="id-1.11.7.39.5.2.3.1.1" class="indexterm"></a>
  59. <code class="function">pgstatindex(regclass) returns record</code>
  60. </span></dt><dd><p>
  61. <code class="function">pgstatindex</code> returns a record showing information
  62. about a B-tree index. For example:
  63. </p><pre class="programlisting">
  64. test=&gt; SELECT * FROM pgstatindex('pg_cast_oid_index');
  65. -[ RECORD 1 ]------+------
  66. version | 2
  67. tree_level | 0
  68. index_size | 16384
  69. root_block_no | 1
  70. internal_pages | 0
  71. leaf_pages | 1
  72. empty_pages | 0
  73. deleted_pages | 0
  74. avg_leaf_density | 54.27
  75. leaf_fragmentation | 0
  76. </pre><p>
  77. </p><p>
  78. The output columns are:
  79. </p><div class="informaltable"><table class="informaltable" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">version</code></td><td><code class="type">integer</code></td><td>B-tree version number</td></tr><tr><td><code class="structfield">tree_level</code></td><td><code class="type">integer</code></td><td>Tree level of the root page</td></tr><tr><td><code class="structfield">index_size</code></td><td><code class="type">bigint</code></td><td>Total index size in bytes</td></tr><tr><td><code class="structfield">root_block_no</code></td><td><code class="type">bigint</code></td><td>Location of root page (zero if none)</td></tr><tr><td><code class="structfield">internal_pages</code></td><td><code class="type">bigint</code></td><td>Number of <span class="quote">“<span class="quote">internal</span>”</span> (upper-level) pages</td></tr><tr><td><code class="structfield">leaf_pages</code></td><td><code class="type">bigint</code></td><td>Number of leaf pages</td></tr><tr><td><code class="structfield">empty_pages</code></td><td><code class="type">bigint</code></td><td>Number of empty pages</td></tr><tr><td><code class="structfield">deleted_pages</code></td><td><code class="type">bigint</code></td><td>Number of deleted pages</td></tr><tr><td><code class="structfield">avg_leaf_density</code></td><td><code class="type">float8</code></td><td>Average density of leaf pages</td></tr><tr><td><code class="structfield">leaf_fragmentation</code></td><td><code class="type">float8</code></td><td>Leaf page fragmentation</td></tr></tbody></table></div><p>
  80. </p><p>
  81. The reported <code class="literal">index_size</code> will normally correspond to one more
  82. page than is accounted for by <code class="literal">internal_pages + leaf_pages +
  83. empty_pages + deleted_pages</code>, because it also includes the
  84. index's metapage.
  85. </p><p>
  86. As with <code class="function">pgstattuple</code>, the results are accumulated
  87. page-by-page, and should not be expected to represent an
  88. instantaneous snapshot of the whole index.
  89. </p></dd><dt><span class="term">
  90. <code class="function">pgstatindex(text) returns record</code>
  91. </span></dt><dd><p>
  92. This is the same as <code class="function">pgstatindex(regclass)</code>, except
  93. that the target index is specified as TEXT. This function is kept
  94. because of backward-compatibility so far, and will be deprecated in
  95. some future release.
  96. </p></dd><dt><span class="term">
  97. <a id="id-1.11.7.39.5.2.5.1.1" class="indexterm"></a>
  98. <code class="function">pgstatginindex(regclass) returns record</code>
  99. </span></dt><dd><p>
  100. <code class="function">pgstatginindex</code> returns a record showing information
  101. about a GIN index. For example:
  102. </p><pre class="programlisting">
  103. test=&gt; SELECT * FROM pgstatginindex('test_gin_index');
  104. -[ RECORD 1 ]--+--
  105. version | 1
  106. pending_pages | 0
  107. pending_tuples | 0
  108. </pre><p>
  109. </p><p>
  110. The output columns are:
  111. </p><div class="informaltable"><table class="informaltable" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">version</code></td><td><code class="type">integer</code></td><td>GIN version number</td></tr><tr><td><code class="structfield">pending_pages</code></td><td><code class="type">integer</code></td><td>Number of pages in the pending list</td></tr><tr><td><code class="structfield">pending_tuples</code></td><td><code class="type">bigint</code></td><td>Number of tuples in the pending list</td></tr></tbody></table></div><p>
  112. </p></dd><dt><span class="term">
  113. <a id="id-1.11.7.39.5.2.6.1.1" class="indexterm"></a>
  114. <code class="function">pgstathashindex(regclass) returns record</code>
  115. </span></dt><dd><p>
  116. <code class="function">pgstathashindex</code> returns a record showing information
  117. about a HASH index. For example:
  118. </p><pre class="programlisting">
  119. test=&gt; select * from pgstathashindex('con_hash_index');
  120. -[ RECORD 1 ]--+-----------------
  121. version | 4
  122. bucket_pages | 33081
  123. overflow_pages | 0
  124. bitmap_pages | 1
  125. unused_pages | 32455
  126. live_items | 10204006
  127. dead_items | 0
  128. free_percent | 61.8005949100872
  129. </pre><p>
  130. </p><p>
  131. The output columns are:
  132. </p><div class="informaltable"><table class="informaltable" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">version</code></td><td><code class="type">integer</code></td><td>HASH version number</td></tr><tr><td><code class="structfield">bucket_pages</code></td><td><code class="type">bigint</code></td><td>Number of bucket pages</td></tr><tr><td><code class="structfield">overflow_pages</code></td><td><code class="type">bigint</code></td><td>Number of overflow pages</td></tr><tr><td><code class="structfield">bitmap_pages</code></td><td><code class="type">bigint</code></td><td>Number of bitmap pages</td></tr><tr><td><code class="structfield">unused_pages</code></td><td><code class="type">bigint</code></td><td>Number of unused pages</td></tr><tr><td><code class="structfield">live_items</code></td><td><code class="type">bigint</code></td><td>Number of live tuples</td></tr><tr><td><code class="structfield">dead_tuples</code></td><td><code class="type">bigint</code></td><td>Number of dead tuples</td></tr><tr><td><code class="structfield">free_percent</code></td><td><code class="type">float</code></td><td>Percentage of free space</td></tr></tbody></table></div><p>
  133. </p></dd><dt><span class="term">
  134. <a id="id-1.11.7.39.5.2.7.1.1" class="indexterm"></a>
  135. <code class="function">pg_relpages(regclass) returns bigint</code>
  136. </span></dt><dd><p>
  137. <code class="function">pg_relpages</code> returns the number of pages in the
  138. relation.
  139. </p></dd><dt><span class="term">
  140. <code class="function">pg_relpages(text) returns bigint</code>
  141. </span></dt><dd><p>
  142. This is the same as <code class="function">pg_relpages(regclass)</code>, except
  143. that the target relation is specified as TEXT. This function is kept
  144. because of backward-compatibility so far, and will be deprecated in
  145. some future release.
  146. </p></dd><dt><span class="term">
  147. <a id="id-1.11.7.39.5.2.9.1.1" class="indexterm"></a>
  148. <code class="function">pgstattuple_approx(regclass) returns record</code>
  149. </span></dt><dd><p>
  150. <code class="function">pgstattuple_approx</code> is a faster alternative to
  151. <code class="function">pgstattuple</code> that returns approximate results.
  152. The argument is the target relation's name or OID.
  153. For example:
  154. </p><pre class="programlisting">
  155. test=&gt; SELECT * FROM pgstattuple_approx('pg_catalog.pg_proc'::regclass);
  156. -[ RECORD 1 ]--------+-------
  157. table_len | 573440
  158. scanned_percent | 2
  159. approx_tuple_count | 2740
  160. approx_tuple_len | 561210
  161. approx_tuple_percent | 97.87
  162. dead_tuple_count | 0
  163. dead_tuple_len | 0
  164. dead_tuple_percent | 0
  165. approx_free_space | 11996
  166. approx_free_percent | 2.09
  167. </pre><p>
  168. The output columns are described in <a class="xref" href="pgstattuple.html#PGSTATAPPROX-COLUMNS" title="Table F.23. pgstattuple_approx Output Columns">Table F.23</a>.
  169. </p><p>
  170. Whereas <code class="function">pgstattuple</code> always performs a
  171. full-table scan and returns an exact count of live and dead tuples
  172. (and their sizes) and free space, <code class="function">pgstattuple_approx</code>
  173. tries to avoid the full-table scan and returns exact dead tuple
  174. statistics along with an approximation of the number and
  175. size of live tuples and free space.
  176. </p><p>
  177. It does this by skipping pages that have only visible tuples
  178. according to the visibility map (if a page has the corresponding VM
  179. bit set, then it is assumed to contain no dead tuples). For such
  180. pages, it derives the free space value from the free space map, and
  181. assumes that the rest of the space on the page is taken up by live
  182. tuples.
  183. </p><p>
  184. For pages that cannot be skipped, it scans each tuple, recording its
  185. presence and size in the appropriate counters, and adding up the
  186. free space on the page. At the end, it estimates the total number of
  187. live tuples based on the number of pages and tuples scanned (in the
  188. same way that VACUUM estimates pg_class.reltuples).
  189. </p><div class="table" id="PGSTATAPPROX-COLUMNS"><p class="title"><strong>Table F.23. <code class="function">pgstattuple_approx</code> Output Columns</strong></p><div class="table-contents"><table class="table" summary="pgstattuple_approx Output Columns" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th>Column</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code class="structfield">table_len</code></td><td><code class="type">bigint</code></td><td>Physical relation length in bytes (exact)</td></tr><tr><td><code class="structfield">scanned_percent</code></td><td><code class="type">float8</code></td><td>Percentage of table scanned</td></tr><tr><td><code class="structfield">approx_tuple_count</code></td><td><code class="type">bigint</code></td><td>Number of live tuples (estimated)</td></tr><tr><td><code class="structfield">approx_tuple_len</code></td><td><code class="type">bigint</code></td><td>Total length of live tuples in bytes (estimated)</td></tr><tr><td><code class="structfield">approx_tuple_percent</code></td><td><code class="type">float8</code></td><td>Percentage of live tuples</td></tr><tr><td><code class="structfield">dead_tuple_count</code></td><td><code class="type">bigint</code></td><td>Number of dead tuples (exact)</td></tr><tr><td><code class="structfield">dead_tuple_len</code></td><td><code class="type">bigint</code></td><td>Total length of dead tuples in bytes (exact)</td></tr><tr><td><code class="structfield">dead_tuple_percent</code></td><td><code class="type">float8</code></td><td>Percentage of dead tuples</td></tr><tr><td><code class="structfield">approx_free_space</code></td><td><code class="type">bigint</code></td><td>Total free space in bytes (estimated)</td></tr><tr><td><code class="structfield">approx_free_percent</code></td><td><code class="type">float8</code></td><td>Percentage of free space</td></tr></tbody></table></div></div><br class="table-break" /><p>
  190. In the above output, the free space figures may not match the
  191. <code class="function">pgstattuple</code> output exactly, because the free
  192. space map gives us an exact figure, but is not guaranteed to be
  193. accurate to the byte.
  194. </p></dd></dl></div></div><div class="sect2" id="id-1.11.7.39.6"><div class="titlepage"><div><div><h3 class="title">F.30.2. Authors</h3></div></div></div><p>
  195. Tatsuo Ishii, Satoshi Nagayasu and Abhijit Menon-Sen
  196. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="pgstatstatements.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="contrib.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="pgtrgm.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">F.29. pg_stat_statements </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> F.31. pg_trgm</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1