gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

178 行
13KB

  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.4. auto_explain</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="auth-delay.html" title="F.3. auth_delay" /><link rel="next" href="bloom.html" title="F.5. bloom" /></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.4. auto_explain</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="auth-delay.html" title="F.3. auth_delay">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="bloom.html" title="F.5. bloom">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="AUTO-EXPLAIN"><div class="titlepage"><div><div><h2 class="title" style="clear: both">F.4. auto_explain</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="auto-explain.html#id-1.11.7.13.5">F.4.1. Configuration Parameters</a></span></dt><dt><span class="sect2"><a href="auto-explain.html#id-1.11.7.13.6">F.4.2. Example</a></span></dt><dt><span class="sect2"><a href="auto-explain.html#id-1.11.7.13.7">F.4.3. Author</a></span></dt></dl></div><a id="id-1.11.7.13.2" class="indexterm"></a><p>
  3. The <code class="filename">auto_explain</code> module provides a means for
  4. logging execution plans of slow statements automatically, without
  5. having to run <a class="xref" href="sql-explain.html" title="EXPLAIN"><span class="refentrytitle">EXPLAIN</span></a>
  6. by hand. This is especially helpful for tracking down un-optimized queries
  7. in large applications.
  8. </p><p>
  9. The module provides no SQL-accessible functions. To use it, simply
  10. load it into the server. You can load it into an individual session:
  11. </p><pre class="programlisting">
  12. LOAD 'auto_explain';
  13. </pre><p>
  14. (You must be superuser to do that.) More typical usage is to preload
  15. it into some or all sessions by including <code class="literal">auto_explain</code> in
  16. <a class="xref" href="runtime-config-client.html#GUC-SESSION-PRELOAD-LIBRARIES">session_preload_libraries</a> or
  17. <a class="xref" href="runtime-config-client.html#GUC-SHARED-PRELOAD-LIBRARIES">shared_preload_libraries</a> in
  18. <code class="filename">postgresql.conf</code>. Then you can track unexpectedly slow queries
  19. no matter when they happen. Of course there is a price in overhead for
  20. that.
  21. </p><div class="sect2" id="id-1.11.7.13.5"><div class="titlepage"><div><div><h3 class="title">F.4.1. Configuration Parameters</h3></div></div></div><p>
  22. There are several configuration parameters that control the behavior of
  23. <code class="filename">auto_explain</code>. Note that the default behavior is
  24. to do nothing, so you must set at least
  25. <code class="varname">auto_explain.log_min_duration</code> if you want any results.
  26. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">
  27. <code class="varname">auto_explain.log_min_duration</code> (<code class="type">integer</code>)
  28. <a id="id-1.11.7.13.5.3.1.1.3" class="indexterm"></a>
  29. </span></dt><dd><p>
  30. <code class="varname">auto_explain.log_min_duration</code> is the minimum statement
  31. execution time, in milliseconds, that will cause the statement's plan to
  32. be logged. Setting this to <code class="literal">0</code> logs all plans.
  33. <code class="literal">-1</code> (the default) disables logging of plans. For
  34. example, if you set it to <code class="literal">250ms</code> then all statements
  35. that run 250ms or longer will be logged. Only superusers can change this
  36. setting.
  37. </p></dd><dt><span class="term">
  38. <code class="varname">auto_explain.log_analyze</code> (<code class="type">boolean</code>)
  39. <a id="id-1.11.7.13.5.3.2.1.3" class="indexterm"></a>
  40. </span></dt><dd><p>
  41. <code class="varname">auto_explain.log_analyze</code> causes <code class="command">EXPLAIN ANALYZE</code>
  42. output, rather than just <code class="command">EXPLAIN</code> output, to be printed
  43. when an execution plan is logged. This parameter is off by default.
  44. Only superusers can change this setting.
  45. </p><div class="note"><h3 class="title">Note</h3><p>
  46. When this parameter is on, per-plan-node timing occurs for all
  47. statements executed, whether or not they run long enough to actually
  48. get logged. This can have an extremely negative impact on performance.
  49. Turning off <code class="varname">auto_explain.log_timing</code> ameliorates the
  50. performance cost, at the price of obtaining less information.
  51. </p></div></dd><dt><span class="term">
  52. <code class="varname">auto_explain.log_buffers</code> (<code class="type">boolean</code>)
  53. <a id="id-1.11.7.13.5.3.3.1.3" class="indexterm"></a>
  54. </span></dt><dd><p>
  55. <code class="varname">auto_explain.log_buffers</code> controls whether buffer
  56. usage statistics are printed when an execution plan is logged; it's
  57. equivalent to the <code class="literal">BUFFERS</code> option of <code class="command">EXPLAIN</code>.
  58. This parameter has no effect
  59. unless <code class="varname">auto_explain.log_analyze</code> is enabled.
  60. This parameter is off by default.
  61. Only superusers can change this setting.
  62. </p></dd><dt><span class="term">
  63. <code class="varname">auto_explain.log_timing</code> (<code class="type">boolean</code>)
  64. <a id="id-1.11.7.13.5.3.4.1.3" class="indexterm"></a>
  65. </span></dt><dd><p>
  66. <code class="varname">auto_explain.log_timing</code> controls whether per-node
  67. timing information is printed when an execution plan is logged; it's
  68. equivalent to the <code class="literal">TIMING</code> option of <code class="command">EXPLAIN</code>.
  69. The overhead of repeatedly reading the system clock can slow down
  70. queries significantly on some systems, so it may be useful to set this
  71. parameter to off when only actual row counts, and not exact times, are
  72. needed.
  73. This parameter has no effect
  74. unless <code class="varname">auto_explain.log_analyze</code> is enabled.
  75. This parameter is on by default.
  76. Only superusers can change this setting.
  77. </p></dd><dt><span class="term">
  78. <code class="varname">auto_explain.log_triggers</code> (<code class="type">boolean</code>)
  79. <a id="id-1.11.7.13.5.3.5.1.3" class="indexterm"></a>
  80. </span></dt><dd><p>
  81. <code class="varname">auto_explain.log_triggers</code> causes trigger
  82. execution statistics to be included when an execution plan is logged.
  83. This parameter has no effect
  84. unless <code class="varname">auto_explain.log_analyze</code> is enabled.
  85. This parameter is off by default.
  86. Only superusers can change this setting.
  87. </p></dd><dt><span class="term">
  88. <code class="varname">auto_explain.log_verbose</code> (<code class="type">boolean</code>)
  89. <a id="id-1.11.7.13.5.3.6.1.3" class="indexterm"></a>
  90. </span></dt><dd><p>
  91. <code class="varname">auto_explain.log_verbose</code> controls whether verbose
  92. details are printed when an execution plan is logged; it's
  93. equivalent to the <code class="literal">VERBOSE</code> option of <code class="command">EXPLAIN</code>.
  94. This parameter is off by default.
  95. Only superusers can change this setting.
  96. </p></dd><dt><span class="term">
  97. <code class="varname">auto_explain.log_settings</code> (<code class="type">boolean</code>)
  98. <a id="id-1.11.7.13.5.3.7.1.3" class="indexterm"></a>
  99. </span></dt><dd><p>
  100. <code class="varname">auto_explain.log_settings</code> controls whether information
  101. about modified configuration options are printed when execution plan is logged.
  102. Only options affecting query planning with value different from the built-in
  103. default value are included in the output. This parameter is off by default.
  104. Only superusers can change this setting.
  105. </p></dd><dt><span class="term">
  106. <code class="varname">auto_explain.log_format</code> (<code class="type">enum</code>)
  107. <a id="id-1.11.7.13.5.3.8.1.3" class="indexterm"></a>
  108. </span></dt><dd><p>
  109. <code class="varname">auto_explain.log_format</code> selects the
  110. <code class="command">EXPLAIN</code> output format to be used.
  111. The allowed values are <code class="literal">text</code>, <code class="literal">xml</code>,
  112. <code class="literal">json</code>, and <code class="literal">yaml</code>. The default is text.
  113. Only superusers can change this setting.
  114. </p></dd><dt><span class="term">
  115. <code class="varname">auto_explain.log_level</code> (<code class="type">enum</code>)
  116. <a id="id-1.11.7.13.5.3.9.1.3" class="indexterm"></a>
  117. </span></dt><dd><p>
  118. <code class="varname">auto_explain.log_level</code> selects the log level at which
  119. auto_explain will log the query plan.
  120. Valid values are <code class="literal">DEBUG5</code>, <code class="literal">DEBUG4</code>,
  121. <code class="literal">DEBUG3</code>, <code class="literal">DEBUG2</code>,
  122. <code class="literal">DEBUG1</code>, <code class="literal">INFO</code>,
  123. <code class="literal">NOTICE</code>, <code class="literal">WARNING</code>,
  124. and <code class="literal">LOG</code>. The default is <code class="literal">LOG</code>.
  125. Only superusers can change this setting.
  126. </p></dd><dt><span class="term">
  127. <code class="varname">auto_explain.log_nested_statements</code> (<code class="type">boolean</code>)
  128. <a id="id-1.11.7.13.5.3.10.1.3" class="indexterm"></a>
  129. </span></dt><dd><p>
  130. <code class="varname">auto_explain.log_nested_statements</code> causes nested
  131. statements (statements executed inside a function) to be considered
  132. for logging. When it is off, only top-level query plans are logged. This
  133. parameter is off by default. Only superusers can change this setting.
  134. </p></dd><dt><span class="term">
  135. <code class="varname">auto_explain.sample_rate</code> (<code class="type">real</code>)
  136. <a id="id-1.11.7.13.5.3.11.1.3" class="indexterm"></a>
  137. </span></dt><dd><p>
  138. <code class="varname">auto_explain.sample_rate</code> causes auto_explain to only
  139. explain a fraction of the statements in each session. The default is 1,
  140. meaning explain all the queries. In case of nested statements, either all
  141. will be explained or none. Only superusers can change this setting.
  142. </p></dd></dl></div><p>
  143. In ordinary usage, these parameters are set
  144. in <code class="filename">postgresql.conf</code>, although superusers can alter them
  145. on-the-fly within their own sessions.
  146. Typical usage might be:
  147. </p><pre class="programlisting">
  148. # postgresql.conf
  149. session_preload_libraries = 'auto_explain'
  150. auto_explain.log_min_duration = '3s'
  151. </pre></div><div class="sect2" id="id-1.11.7.13.6"><div class="titlepage"><div><div><h3 class="title">F.4.2. Example</h3></div></div></div><pre class="programlisting">
  152. postgres=# LOAD 'auto_explain';
  153. postgres=# SET auto_explain.log_min_duration = 0;
  154. postgres=# SET auto_explain.log_analyze = true;
  155. postgres=# SELECT count(*)
  156. FROM pg_class, pg_index
  157. WHERE oid = indrelid AND indisunique;
  158. </pre><p>
  159. This might produce log output such as:
  160. </p><pre class="screen">
  161. LOG: duration: 3.651 ms plan:
  162. Query Text: SELECT count(*)
  163. FROM pg_class, pg_index
  164. WHERE oid = indrelid AND indisunique;
  165. Aggregate (cost=16.79..16.80 rows=1 width=0) (actual time=3.626..3.627 rows=1 loops=1)
  166. -&gt; Hash Join (cost=4.17..16.55 rows=92 width=0) (actual time=3.349..3.594 rows=92 loops=1)
  167. Hash Cond: (pg_class.oid = pg_index.indrelid)
  168. -&gt; Seq Scan on pg_class (cost=0.00..9.55 rows=255 width=4) (actual time=0.016..0.140 rows=255 loops=1)
  169. -&gt; Hash (cost=3.02..3.02 rows=92 width=4) (actual time=3.238..3.238 rows=92 loops=1)
  170. Buckets: 1024 Batches: 1 Memory Usage: 4kB
  171. -&gt; Seq Scan on pg_index (cost=0.00..3.02 rows=92 width=4) (actual time=0.008..3.187 rows=92 loops=1)
  172. Filter: indisunique
  173. </pre></div><div class="sect2" id="id-1.11.7.13.7"><div class="titlepage"><div><div><h3 class="title">F.4.3. Author</h3></div></div></div><p>
  174. Takahiro Itagaki <code class="email">&lt;<a class="email" href="mailto:itagaki.takahiro@oss.ntt.co.jp">itagaki.takahiro@oss.ntt.co.jp</a>&gt;</code>
  175. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="auth-delay.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="bloom.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">F.3. auth_delay </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> F.5. bloom</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1