codekingpro/portable-devtools
114k
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 Vsnapshot" /><link rel="prev" href="app-reindexdb.html" title="reindexdb" /><link rel="next" href="reference-server.html" title="PostgreSQL Server Applications" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center"><span 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 16.3 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 /></div><div class="refentry" id="APP-VACUUMDB"><div class="titlepage"></div><a id="id-1.9.4.22.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.22.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">-t</code> | <code class="option">--table</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.22.4.2"><code class="command">vacuumdb</code> [<em class="replaceable"><code>connection-option</code></em>...] [<em class="replaceable"><code>option</code></em>...] 9 [10 11 [12 <code class="option">-n</code> | <code class="option">--schema</code> 13 <em class="replaceable"><code>schema</code></em>14 ]15 | 16 [17 <code class="option">-N</code> | <code class="option">--exclude-schema</code> 18 <em class="replaceable"><code>schema</code></em>19 ]20 21 ]22 ... [<em class="replaceable"><code>dbname</code></em>]</p></div><div class="cmdsynopsis"><p id="id-1.9.4.22.4.3"><code class="command">vacuumdb</code> [<em class="replaceable"><code>connection-option</code></em>...] [<em class="replaceable"><code>option</code></em>...] <code class="option">-a</code> | <code class="option">--all</code> </p></div></div><div class="refsect1" id="id-1.9.4.22.5"><h2>Description</h2><p>23 <span class="application">vacuumdb</span> is a utility for cleaning a24 <span class="productname">PostgreSQL</span> database.25 <span class="application">vacuumdb</span> will also generate internal statistics26 used by the <span class="productname">PostgreSQL</span> query optimizer.27 </p><p>28 <span class="application">vacuumdb</span> is a wrapper around the SQL29 command <a class="link" href="sql-vacuum.html" title="VACUUM"><code class="command">VACUUM</code></a>.30 There is no effective difference between vacuuming and analyzing31 databases via this utility and via other methods for accessing the32 server.33 </p></div><div class="refsect1" id="id-1.9.4.22.6"><h2>Options</h2><p>34 <span class="application">vacuumdb</span> accepts the following command-line arguments:35 </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>36 Vacuum all databases.37 </p></dd><dt><span class="term"><code class="option">--buffer-usage-limit <em class="replaceable"><code>size</code></em></code></span></dt><dd><p>38 Specifies the39 <a class="glossterm" href="glossary.html#GLOSSARY-BUFFER-ACCESS-STRATEGY"><em class="glossterm"><a class="glossterm" href="glossary.html#GLOSSARY-BUFFER-ACCESS-STRATEGY" title="Buffer Access Strategy">Buffer Access Strategy</a></em></a>40 ring buffer size for a given invocation of <span class="application">vacuumdb</span>.41 This size is used to calculate the number of shared buffers which will42 be reused as part of this strategy. See <a class="xref" href="sql-vacuum.html" title="VACUUM"><span class="refentrytitle">VACUUM</span></a>.43 </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>44 Specifies the name of the database to be cleaned or analyzed,45 when <code class="option">-a</code>/<code class="option">--all</code> is not used.46 If this is not specified, the database name is read47 from the environment variable <code class="envar">PGDATABASE</code>. If48 that is not set, the user name specified for the connection is49 used. The <em class="replaceable"><code>dbname</code></em> can be a <a class="link" href="libpq-connect.html#LIBPQ-CONNSTRING" title="34.1.1. Connection Strings">connection string</a>. If so,50 connection string parameters will override any conflicting command51 line options.52 </p></dd><dt><span class="term"><code class="option">--disable-page-skipping</code></span></dt><dd><p>53 Disable skipping pages based on the contents of the visibility map.54 </p></dd><dt><span class="term"><code class="option">-e</code><br /></span><span class="term"><code class="option">--echo</code></span></dt><dd><p>55 Echo the commands that <span class="application">vacuumdb</span> generates56 and sends to the server.57 </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>58 Perform <span class="quote">“<span class="quote">full</span>”</span> vacuuming.59 </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>60 Aggressively <span class="quote">“<span class="quote">freeze</span>”</span> tuples.61 </p></dd><dt><span class="term"><code class="option">--force-index-cleanup</code></span></dt><dd><p>62 Always remove index entries pointing to dead tuples.63 </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>64 Execute the vacuum or analyze commands in parallel by running65 <em class="replaceable"><code>njobs</code></em>66 commands simultaneously. This option may reduce the processing time67 but it also increases the load on the database server.68 </p><p>69 <span class="application">vacuumdb</span> will open70 <em class="replaceable"><code>njobs</code></em> connections to the71 database, so make sure your <a class="xref" href="runtime-config-connection.html#GUC-MAX-CONNECTIONS">max_connections</a>72 setting is high enough to accommodate all connections.73 </p><p>74 Note that using this mode together with the <code class="option">-f</code>75 (<code class="literal">FULL</code>) option might cause deadlock failures if76 certain system catalogs are processed in parallel.77 </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>78 Only execute the vacuum or analyze commands on tables with a multixact79 ID age of at least <em class="replaceable"><code>mxid_age</code></em>.80 This setting is useful for prioritizing tables to process to prevent81 multixact ID wraparound (see82 <a class="xref" href="routine-vacuuming.html#VACUUM-FOR-MULTIXACT-WRAPAROUND" title="25.1.5.1. Multixacts and Wraparound">Section 25.1.5.1</a>).83 </p><p>84 For the purposes of this option, the multixact ID age of a relation is85 the greatest of the ages of the main relation and its associated86 <acronym class="acronym">TOAST</acronym> table, if one exists. Since the commands87 issued by <span class="application">vacuumdb</span> will also process the88 <acronym class="acronym">TOAST</acronym> table for the relation if necessary, it does89 not need to be considered separately.90 </p></dd><dt><span class="term"><code class="option">--min-xid-age <em class="replaceable"><code>xid_age</code></em></code></span></dt><dd><p>91 Only execute the vacuum or analyze commands on tables with a92 transaction ID age of at least93 <em class="replaceable"><code>xid_age</code></em>. This setting94 is useful for prioritizing tables to process to prevent transaction95 ID wraparound (see <a class="xref" href="routine-vacuuming.html#VACUUM-FOR-WRAPAROUND" title="25.1.5. Preventing Transaction ID Wraparound Failures">Section 25.1.5</a>).96 </p><p>97 For the purposes of this option, the transaction ID age of a relation98 is the greatest of the ages of the main relation and its associated99 <acronym class="acronym">TOAST</acronym> table, if one exists. Since the commands100 issued by <span class="application">vacuumdb</span> will also process the101 <acronym class="acronym">TOAST</acronym> table for the relation if necessary, it does102 not need to be considered separately.103 </p></dd><dt><span class="term"><code class="option">-n <em class="replaceable"><code>schema</code></em></code><br /></span><span class="term"><code class="option">--schema=<em class="replaceable"><code>schema</code></em></code></span></dt><dd><p>104 Clean or analyze all tables in105 <em class="replaceable"><code>schema</code></em> only. Multiple106 schemas can be vacuumed by writing multiple <code class="option">-n</code> switches.107 </p></dd><dt><span class="term"><code class="option">-N <em class="replaceable"><code>schema</code></em></code><br /></span><span class="term"><code class="option">--exclude-schema=<em class="replaceable"><code>schema</code></em></code></span></dt><dd><p>108 Do not clean or analyze any tables in109 <em class="replaceable"><code>schema</code></em>. Multiple schemas110 can be excluded by writing multiple <code class="option">-N</code> switches.111 </p></dd><dt><span class="term"><code class="option">--no-index-cleanup</code></span></dt><dd><p>112 Do not remove index entries pointing to dead tuples.113 </p></dd><dt><span class="term"><code class="option">--no-process-main</code></span></dt><dd><p>114 Skip the main relation.115 </p></dd><dt><span class="term"><code class="option">--no-process-toast</code></span></dt><dd><p>116 Skip the TOAST table associated with the table to vacuum, if any.117 </p></dd><dt><span class="term"><code class="option">--no-truncate</code></span></dt><dd><p>118 Do not truncate empty pages at the end of the table.119 </p></dd><dt><span class="term"><code class="option">-P <em class="replaceable"><code>parallel_workers</code></em></code><br /></span><span class="term"><code class="option">--parallel=<em class="replaceable"><code>parallel_workers</code></em></code></span></dt><dd><p>120 Specify the number of parallel workers for <em class="firstterm">parallel vacuum</em>.121 This allows the vacuum to leverage multiple CPUs to process indexes.122 See <a class="xref" href="sql-vacuum.html" title="VACUUM"><span class="refentrytitle">VACUUM</span></a>.123 </p></dd><dt><span class="term"><code class="option">-q</code><br /></span><span class="term"><code class="option">--quiet</code></span></dt><dd><p>124 Do not display progress messages.125 </p></dd><dt><span class="term"><code class="option">--skip-locked</code></span></dt><dd><p>126 Skip relations that cannot be immediately locked for processing.127 </p></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>128 Clean or analyze <em class="replaceable"><code>table</code></em> only.129 Column names can be specified only in conjunction with130 the <code class="option">--analyze</code> or <code class="option">--analyze-only</code> options.131 Multiple tables can be vacuumed by writing multiple132 <code class="option">-t</code> switches.133 </p><div class="tip"><h3 class="title">Tip</h3><p>134 If you specify columns, you probably have to escape the parentheses135 from the shell. (See examples below.)136 </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>137 Print detailed information during processing.138 </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>139 Print the <span class="application">vacuumdb</span> version and exit.140 </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>141 Also calculate statistics for use by the optimizer.142 </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>143 Only calculate statistics for use by the optimizer (no vacuum).144 </p></dd><dt><span class="term"><code class="option">--analyze-in-stages</code></span></dt><dd><p>145 Only calculate statistics for use by the optimizer (no vacuum),146 like <code class="option">--analyze-only</code>. Run three147 stages of analyze; the first stage uses the lowest possible statistics148 target (see <a class="xref" href="runtime-config-query.html#GUC-DEFAULT-STATISTICS-TARGET">default_statistics_target</a>)149 to produce usable statistics faster, and subsequent stages build the150 full statistics.151 </p><p>152 This option is only useful to analyze a database that currently has153 no statistics or has wholly incorrect ones, such as if it is newly154 populated from a restored dump or by <code class="command">pg_upgrade</code>.155 Be aware that running with this option in a database with existing156 statistics may cause the query optimizer choices to become157 transiently worse due to the low statistics targets of the early158 stages.159 </p></dd><dt><span class="term"><code class="option">-?</code><br /></span><span class="term"><code class="option">--help</code></span></dt><dd><p>160 Show help about <span class="application">vacuumdb</span> command line161 arguments, and exit.162 </p></dd></dl></div><p>163 </p><p>164 <span class="application">vacuumdb</span> also accepts165 the following command-line arguments for connection parameters:166 </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>167 Specifies the host name of the machine on which the server168 is running. If the value begins with a slash, it is used169 as the directory for the Unix domain socket.170 </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>171 Specifies the TCP port or local Unix domain socket file172 extension on which the server173 is listening for connections.174 </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>175 User name to connect as.176 </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>177 Never issue a password prompt. If the server requires178 password authentication and a password is not available by179 other means such as a <code class="filename">.pgpass</code> file, the180 connection attempt will fail. This option can be useful in181 batch jobs and scripts where no user is present to enter a182 password.183 </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>184 Force <span class="application">vacuumdb</span> to prompt for a185 password before connecting to a database.186 </p><p>187 This option is never essential, since188 <span class="application">vacuumdb</span> will automatically prompt189 for a password if the server demands password authentication.190 However, <span class="application">vacuumdb</span> will waste a191 connection attempt finding out that the server wants a password.192 In some cases it is worth typing <code class="option">-W</code> to avoid the extra193 connection attempt.194 </p></dd><dt><span class="term"><code class="option">--maintenance-db=<em class="replaceable"><code>dbname</code></em></code></span></dt><dd><p>195 Specifies the name of the database to connect to to discover which196 databases should be vacuumed,197 when <code class="option">-a</code>/<code class="option">--all</code> is used.198 If not specified, the <code class="literal">postgres</code> database will be used,199 or if that does not exist, <code class="literal">template1</code> will be used.200 This can be a <a class="link" href="libpq-connect.html#LIBPQ-CONNSTRING" title="34.1.1. Connection Strings">connection201 string</a>. If so, connection string parameters will override any202 conflicting command line options. Also, connection string parameters203 other than the database name itself will be re-used when connecting204 to other databases.205 </p></dd></dl></div><p>206 </p></div><div class="refsect1" id="id-1.9.4.22.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>207 Default connection parameters208 </p></dd><dt><span class="term"><code class="envar">PG_COLOR</code></span></dt><dd><p>209 Specifies whether to use color in diagnostic messages. Possible values210 are <code class="literal">always</code>, <code class="literal">auto</code> and211 <code class="literal">never</code>.212 </p></dd></dl></div><p>213 This utility, like most other <span class="productname">PostgreSQL</span> utilities,214 also uses the environment variables supported by <span class="application">libpq</span>215 (see <a class="xref" href="libpq-envars.html" title="34.15. Environment Variables">Section 34.15</a>).216 </p></div><div class="refsect1" id="id-1.9.4.22.8"><h2>Diagnostics</h2><p>217 In case of difficulty, see <a class="xref" href="sql-vacuum.html" title="VACUUM"><span class="refentrytitle">VACUUM</span></a>218 and <a class="xref" href="app-psql.html" title="psql"><span class="refentrytitle"><span class="application">psql</span></span></a> for219 discussions of potential problems and error messages.220 The database server must be running at the221 targeted host. Also, any default connection settings and environment222 variables used by the <span class="application">libpq</span> front-end223 library will apply.224 </p></div><div class="refsect1" id="id-1.9.4.22.9"><h2>Notes</h2><p>225 <span class="application">vacuumdb</span> might need to connect several226 times to the <span class="productname">PostgreSQL</span> server, asking227 for a password each time. It is convenient to have a228 <code class="filename">~/.pgpass</code> file in such cases. See <a class="xref" href="libpq-pgpass.html" title="34.16. The Password File">Section 34.16</a> for more information.229 </p></div><div class="refsect1" id="id-1.9.4.22.10"><h2>Examples</h2><p>230 To clean the database <code class="literal">test</code>:231</p><pre class="screen">232<code class="prompt">$ </code><strong class="userinput"><code>vacuumdb test</code></strong>233</pre><p>234 </p><p>235 To clean and analyze for the optimizer a database named236 <code class="literal">bigdb</code>:237</p><pre class="screen">238<code class="prompt">$ </code><strong class="userinput"><code>vacuumdb --analyze bigdb</code></strong>239</pre><p>240 </p><p>241 To clean a single table242 <code class="literal">foo</code> in a database named243 <code class="literal">xyzzy</code>, and analyze a single column244 <code class="literal">bar</code> of the table for the optimizer:245</p><pre class="screen">246<code class="prompt">$ </code><strong class="userinput"><code>vacuumdb --analyze --verbose --table='foo(bar)' xyzzy</code></strong>247</pre><p>248 To clean all tables in the <code class="literal">foo</code> and <code class="literal">bar</code> schemas249 in a database named <code class="literal">xyzzy</code>:250</p><pre class="screen">251<code class="prompt">$ </code><strong class="userinput"><code>vacuumdb --schema='foo' --schema='bar' xyzzy</code></strong>252</pre></div><div class="refsect1" id="id-1.9.4.22.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" title="reindexdb">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference-client.html" title="PostgreSQL Client Applications">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="reference-server.html" title="PostgreSQL Server Applications">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" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> PostgreSQL Server Applications</td></tr></table></div></body></html>