gooderp18绿色标准版
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

205 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>vacuumdb</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="app-reindexdb.html" title="reindexdb" /><link rel="next" href="reference-server.html" title="PostgreSQL Server Applications" /></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"><span xmlns="http://www.w3.org/1999/xhtml" class="application">vacuumdb</span></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="app-reindexdb.html" title="reindexdb">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="reference-client.html" title="PostgreSQL Client Applications">Up</a></td><th width="60%" align="center">PostgreSQL Client Applications</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="reference-server.html" title="PostgreSQL Server Applications">Next</a></td></tr></table><hr></hr></div><div class="refentry" id="APP-VACUUMDB"><div class="titlepage"></div><a id="id-1.9.4.20.1" class="indexterm"></a><div class="refnamediv"><h2><span class="refentrytitle"><span class="application">vacuumdb</span></span></h2><p>vacuumdb — garbage-collect and analyze a <span class="productname">PostgreSQL</span> database</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="cmdsynopsis"><p id="id-1.9.4.20.4.1"><code class="command">vacuumdb</code> [<em class="replaceable"><code>connection-option</code></em>...] [<em class="replaceable"><code>option</code></em>...]
  3. [
  4. <code class="option">--table</code> | <code class="option">-t</code>
  5. <em class="replaceable"><code>table</code></em>
  6. [( <em class="replaceable"><code>column</code></em> [,...] )]
  7. ]
  8. ... [<em class="replaceable"><code>dbname</code></em>]</p></div><div class="cmdsynopsis"><p id="id-1.9.4.20.4.2"><code class="command">vacuumdb</code> [<em class="replaceable"><code>connection-option</code></em>...] [<em class="replaceable"><code>option</code></em>...] <code class="option">--all</code> | <code class="option">-a</code> </p></div></div><div class="refsect1" id="id-1.9.4.20.5"><h2>Description</h2><p>
  9. <span class="application">vacuumdb</span> is a utility for cleaning a
  10. <span class="productname">PostgreSQL</span> database.
  11. <span class="application">vacuumdb</span> will also generate internal statistics
  12. used by the <span class="productname">PostgreSQL</span> query optimizer.
  13. </p><p>
  14. <span class="application">vacuumdb</span> is a wrapper around the SQL
  15. command <a class="xref" href="sql-vacuum.html" title="VACUUM"><span class="refentrytitle">VACUUM</span></a>.
  16. There is no effective difference between vacuuming and analyzing
  17. databases via this utility and via other methods for accessing the
  18. server.
  19. </p></div><div class="refsect1" id="id-1.9.4.20.6"><h2>Options</h2><p>
  20. <span class="application">vacuumdb</span> accepts the following command-line arguments:
  21. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-a</code><br /></span><span class="term"><code class="option">--all</code></span></dt><dd><p>
  22. Vacuum all databases.
  23. </p></dd><dt><span class="term"><code class="option">[<span class="optional">-d</span>] <em class="replaceable"><code>dbname</code></em></code><br /></span><span class="term"><code class="option">[<span class="optional">--dbname=</span>]<em class="replaceable"><code>dbname</code></em></code></span></dt><dd><p>
  24. Specifies the name of the database to be cleaned or analyzed.
  25. If this is not specified and <code class="option">-a</code> (or
  26. <code class="option">--all</code>) is not used, the database name is read
  27. from the environment variable <code class="envar">PGDATABASE</code>. If
  28. that is not set, the user name specified for the connection is
  29. used.
  30. </p></dd><dt><span class="term"><code class="option">--disable-page-skipping</code></span></dt><dd><p>
  31. Disable skipping pages based on the contents of the visibility map.
  32. </p><div class="note"><h3 class="title">Note</h3><p>
  33. This option is only available for servers running
  34. <span class="productname">PostgreSQL</span> 9.6 and later.
  35. </p></div></dd><dt><span class="term"><code class="option">-e</code><br /></span><span class="term"><code class="option">--echo</code></span></dt><dd><p>
  36. Echo the commands that <span class="application">vacuumdb</span> generates
  37. and sends to the server.
  38. </p></dd><dt><span class="term"><code class="option">-f</code><br /></span><span class="term"><code class="option">--full</code></span></dt><dd><p>
  39. Perform <span class="quote">“<span class="quote">full</span>”</span> vacuuming.
  40. </p></dd><dt><span class="term"><code class="option">-F</code><br /></span><span class="term"><code class="option">--freeze</code></span></dt><dd><p>
  41. Aggressively <span class="quote">“<span class="quote">freeze</span>”</span> tuples.
  42. </p></dd><dt><span class="term"><code class="option">-j <em class="replaceable"><code>njobs</code></em></code><br /></span><span class="term"><code class="option">--jobs=<em class="replaceable"><code>njobs</code></em></code></span></dt><dd><p>
  43. Execute the vacuum or analyze commands in parallel by running
  44. <em class="replaceable"><code>njobs</code></em>
  45. commands simultaneously. This option reduces the time of the
  46. processing but it also increases the load on the database server.
  47. </p><p>
  48. <span class="application">vacuumdb</span> will open
  49. <em class="replaceable"><code>njobs</code></em> connections to the
  50. database, so make sure your <a class="xref" href="runtime-config-connection.html#GUC-MAX-CONNECTIONS">max_connections</a>
  51. setting is high enough to accommodate all connections.
  52. </p><p>
  53. Note that using this mode together with the <code class="option">-f</code>
  54. (<code class="literal">FULL</code>) option might cause deadlock failures if
  55. certain system catalogs are processed in parallel.
  56. </p></dd><dt><span class="term"><code class="option">--min-mxid-age <em class="replaceable"><code>mxid_age</code></em></code></span></dt><dd><p>
  57. Only execute the vacuum or analyze commands on tables with a multixact
  58. ID age of at least <em class="replaceable"><code>mxid_age</code></em>.
  59. This setting is useful for prioritizing tables to process to prevent
  60. multixact ID wraparound (see
  61. <a class="xref" href="routine-vacuuming.html#VACUUM-FOR-MULTIXACT-WRAPAROUND" title="24.1.5.1. Multixacts and Wraparound">Section 24.1.5.1</a>).
  62. </p><p>
  63. For the purposes of this option, the multixact ID age of a relation is
  64. the greatest of the ages of the main relation and its associated
  65. <acronym class="acronym">TOAST</acronym> table, if one exists. Since the commands
  66. issued by <span class="application">vacuumdb</span> will also process the
  67. <acronym class="acronym">TOAST</acronym> table for the relation if necessary, it does
  68. not need to be considered separately.
  69. </p><div class="note"><h3 class="title">Note</h3><p>
  70. This option is only available for servers running
  71. <span class="productname">PostgreSQL</span> 9.6 and later.
  72. </p></div></dd><dt><span class="term"><code class="option">--min-xid-age <em class="replaceable"><code>xid_age</code></em></code></span></dt><dd><p>
  73. Only execute the vacuum or analyze commands on tables with a
  74. transaction ID age of at least
  75. <em class="replaceable"><code>xid_age</code></em>. This setting
  76. is useful for prioritizing tables to process to prevent transaction
  77. ID wraparound (see <a class="xref" href="routine-vacuuming.html#VACUUM-FOR-WRAPAROUND" title="24.1.5. Preventing Transaction ID Wraparound Failures">Section 24.1.5</a>).
  78. </p><p>
  79. For the purposes of this option, the transaction ID age of a relation
  80. is the greatest of the ages of the main relation and its associated
  81. <acronym class="acronym">TOAST</acronym> table, if one exists. Since the commands
  82. issued by <span class="application">vacuumdb</span> will also process the
  83. <acronym class="acronym">TOAST</acronym> table for the relation if necessary, it does
  84. not need to be considered separately.
  85. </p><div class="note"><h3 class="title">Note</h3><p>
  86. This option is only available for servers running
  87. <span class="productname">PostgreSQL</span> 9.6 and later.
  88. </p></div></dd><dt><span class="term"><code class="option">-q</code><br /></span><span class="term"><code class="option">--quiet</code></span></dt><dd><p>
  89. Do not display progress messages.
  90. </p></dd><dt><span class="term"><code class="option">--skip-locked</code></span></dt><dd><p>
  91. Skip relations that cannot be immediately locked for processing.
  92. </p><div class="note"><h3 class="title">Note</h3><p>
  93. This option is only available for servers running
  94. <span class="productname">PostgreSQL</span> 12 and later.
  95. </p></div></dd><dt><span class="term"><code class="option">-t <em class="replaceable"><code>table</code></em> [ (<em class="replaceable"><code>column</code></em> [,...]) ]</code><br /></span><span class="term"><code class="option">--table=<em class="replaceable"><code>table</code></em> [ (<em class="replaceable"><code>column</code></em> [,...]) ]</code></span></dt><dd><p>
  96. Clean or analyze <em class="replaceable"><code>table</code></em> only.
  97. Column names can be specified only in conjunction with
  98. the <code class="option">--analyze</code> or <code class="option">--analyze-only</code> options.
  99. Multiple tables can be vacuumed by writing multiple
  100. <code class="option">-t</code> switches.
  101. </p><div class="tip"><h3 class="title">Tip</h3><p>
  102. If you specify columns, you probably have to escape the parentheses
  103. from the shell. (See examples below.)
  104. </p></div></dd><dt><span class="term"><code class="option">-v</code><br /></span><span class="term"><code class="option">--verbose</code></span></dt><dd><p>
  105. Print detailed information during processing.
  106. </p></dd><dt><span class="term"><code class="option">-V</code><br /></span><span class="term"><code class="option">--version</code></span></dt><dd><p>
  107. Print the <span class="application">vacuumdb</span> version and exit.
  108. </p></dd><dt><span class="term"><code class="option">-z</code><br /></span><span class="term"><code class="option">--analyze</code></span></dt><dd><p>
  109. Also calculate statistics for use by the optimizer.
  110. </p></dd><dt><span class="term"><code class="option">-Z</code><br /></span><span class="term"><code class="option">--analyze-only</code></span></dt><dd><p>
  111. Only calculate statistics for use by the optimizer (no vacuum).
  112. </p></dd><dt><span class="term"><code class="option">--analyze-in-stages</code></span></dt><dd><p>
  113. Only calculate statistics for use by the optimizer (no vacuum),
  114. like <code class="option">--analyze-only</code>. Run several (currently three)
  115. stages of analyze with different configuration settings, to produce
  116. usable statistics faster.
  117. </p><p>
  118. This option is useful to analyze a database that was newly populated
  119. from a restored dump or by <code class="command">pg_upgrade</code>. This option
  120. will try to create some statistics as fast as possible, to make the
  121. database usable, and then produce full statistics in the subsequent
  122. stages.
  123. </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>
  124. Show help about <span class="application">vacuumdb</span> command line
  125. arguments, and exit.
  126. </p></dd></dl></div><p>
  127. </p><p>
  128. <span class="application">vacuumdb</span> also accepts
  129. the following command-line arguments for connection parameters:
  130. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="option">-h <em class="replaceable"><code>host</code></em></code><br /></span><span class="term"><code class="option">--host=<em class="replaceable"><code>host</code></em></code></span></dt><dd><p>
  131. Specifies the host name of the machine on which the server
  132. is running. If the value begins with a slash, it is used
  133. as the directory for the Unix domain socket.
  134. </p></dd><dt><span class="term"><code class="option">-p <em class="replaceable"><code>port</code></em></code><br /></span><span class="term"><code class="option">--port=<em class="replaceable"><code>port</code></em></code></span></dt><dd><p>
  135. Specifies the TCP port or local Unix domain socket file
  136. extension on which the server
  137. is listening for connections.
  138. </p></dd><dt><span class="term"><code class="option">-U <em class="replaceable"><code>username</code></em></code><br /></span><span class="term"><code class="option">--username=<em class="replaceable"><code>username</code></em></code></span></dt><dd><p>
  139. User name to connect as.
  140. </p></dd><dt><span class="term"><code class="option">-w</code><br /></span><span class="term"><code class="option">--no-password</code></span></dt><dd><p>
  141. Never issue a password prompt. If the server requires
  142. password authentication and a password is not available by
  143. other means such as a <code class="filename">.pgpass</code> file, the
  144. connection attempt will fail. This option can be useful in
  145. batch jobs and scripts where no user is present to enter a
  146. password.
  147. </p></dd><dt><span class="term"><code class="option">-W</code><br /></span><span class="term"><code class="option">--password</code></span></dt><dd><p>
  148. Force <span class="application">vacuumdb</span> to prompt for a
  149. password before connecting to a database.
  150. </p><p>
  151. This option is never essential, since
  152. <span class="application">vacuumdb</span> will automatically prompt
  153. for a password if the server demands password authentication.
  154. However, <span class="application">vacuumdb</span> will waste a
  155. connection attempt finding out that the server wants a password.
  156. In some cases it is worth typing <code class="option">-W</code> to avoid the extra
  157. connection attempt.
  158. </p></dd><dt><span class="term"><code class="option">--maintenance-db=<em class="replaceable"><code>dbname</code></em></code></span></dt><dd><p>
  159. Specifies the name of the database to connect to discover what other
  160. databases should be vacuumed. If not specified, the
  161. <code class="literal">postgres</code> database will be used,
  162. and if that does not exist, <code class="literal">template1</code> will be used.
  163. </p></dd></dl></div><p>
  164. </p></div><div class="refsect1" id="id-1.9.4.20.7"><h2>Environment</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="envar">PGDATABASE</code><br /></span><span class="term"><code class="envar">PGHOST</code><br /></span><span class="term"><code class="envar">PGPORT</code><br /></span><span class="term"><code class="envar">PGUSER</code></span></dt><dd><p>
  165. Default connection parameters
  166. </p></dd><dt><span class="term"><code class="envar">PG_COLOR</code></span></dt><dd><p>
  167. Specifies whether to use color in diagnostic messages. Possible values
  168. are <code class="literal">always</code>, <code class="literal">auto</code> and
  169. <code class="literal">never</code>.
  170. </p></dd></dl></div><p>
  171. This utility, like most other <span class="productname">PostgreSQL</span> utilities,
  172. also uses the environment variables supported by <span class="application">libpq</span>
  173. (see <a class="xref" href="libpq-envars.html" title="33.14. Environment Variables">Section 33.14</a>).
  174. </p></div><div class="refsect1" id="id-1.9.4.20.8"><h2>Diagnostics</h2><p>
  175. In case of difficulty, see <a class="xref" href="sql-vacuum.html" title="VACUUM"><span class="refentrytitle">VACUUM</span></a>
  176. and <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a> for
  177. discussions of potential problems and error messages.
  178. The database server must be running at the
  179. targeted host. Also, any default connection settings and environment
  180. variables used by the <span class="application">libpq</span> front-end
  181. library will apply.
  182. </p></div><div class="refsect1" id="id-1.9.4.20.9"><h2>Notes</h2><p>
  183. <span class="application">vacuumdb</span> might need to connect several
  184. times to the <span class="productname">PostgreSQL</span> server, asking
  185. for a password each time. It is convenient to have a
  186. <code class="filename">~/.pgpass</code> file in such cases. See <a class="xref" href="libpq-pgpass.html" title="33.15. The Password File">Section 33.15</a> for more information.
  187. </p></div><div class="refsect1" id="id-1.9.4.20.10"><h2>Examples</h2><p>
  188. To clean the database <code class="literal">test</code>:
  189. </p><pre class="screen">
  190. <code class="prompt">$ </code><strong class="userinput"><code>vacuumdb test</code></strong>
  191. </pre><p>
  192. </p><p>
  193. To clean and analyze for the optimizer a database named
  194. <code class="literal">bigdb</code>:
  195. </p><pre class="screen">
  196. <code class="prompt">$ </code><strong class="userinput"><code>vacuumdb --analyze bigdb</code></strong>
  197. </pre><p>
  198. </p><p>
  199. To clean a single table
  200. <code class="literal">foo</code> in a database named
  201. <code class="literal">xyzzy</code>, and analyze a single column
  202. <code class="literal">bar</code> of the table for the optimizer:
  203. </p><pre class="screen">
  204. <code class="prompt">$ </code><strong class="userinput"><code>vacuumdb --analyze --verbose --table='foo(bar)' xyzzy</code></strong>
  205. </pre></div><div class="refsect1" id="id-1.9.4.20.11"><h2>See Also</h2><span class="simplelist"><a class="xref" href="sql-vacuum.html" title="VACUUM"><span class="refentrytitle">VACUUM</span></a></span></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="app-reindexdb.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-client.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="reference-server.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top"><span class="application">reindexdb</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> PostgreSQL Server Applications</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1