3 .\" Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
6 .\" Manual: PostgreSQL 18.0 Documentation
7 .\" Source: PostgreSQL 18.0
10 .TH "VACUUMDB" "1" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 vacuumdb \- garbage\-collect and analyze a PostgreSQL database
33 .HP \w'\fBvacuumdb\fR\ 'u
34 \fBvacuumdb\fR [\fIconnection\-option\fR...] [\fIoption\fR...] [\ \fB\-t\fR\ |\ \fB\-\-table\fR\ \fItable\fR\ [(\ \fIcolumn\fR\ [,\&.\&.\&.]\ )]\ ]... [\fIdbname\fR\ |\ \fB\-a\fR\ |\ \fB\-\-all\fR]
35 .HP \w'\fBvacuumdb\fR\ 'u
36 \fBvacuumdb\fR [\fIconnection\-option\fR...] [\fIoption\fR...] [\ \fB\-n\fR\ |\ \fB\-\-schema\fR\ \fIschema\fR\ ]... [\fIdbname\fR\ |\ \fB\-a\fR\ |\ \fB\-\-all\fR]
37 .HP \w'\fBvacuumdb\fR\ 'u
38 \fBvacuumdb\fR [\fIconnection\-option\fR...] [\fIoption\fR...] [\ \fB\-N\fR\ |\ \fB\-\-exclude\-schema\fR\ \fIschema\fR\ ]... [\fIdbname\fR\ |\ \fB\-a\fR\ |\ \fB\-\-all\fR]
42 is a utility for cleaning a
46 will also generate internal statistics used by the
51 is a wrapper around the SQL command
52 \fBVACUUM\fR\&. There is no effective difference between vacuuming and analyzing databases via this utility and via other methods for accessing the server\&.
56 accepts the following command\-line arguments:
62 Vacuum all databases\&.
65 \fB\-\-buffer\-usage\-limit \fR\fB\fIsize\fR\fR
68 Buffer Access Strategy
69 ring buffer size for a given invocation of
70 vacuumdb\&. This size is used to calculate the number of shared buffers which will be reused as part of this strategy\&. See
74 \fB[\-d]\fR\fB \fR\fB\fIdbname\fR\fR
76 \fB[\-\-dbname=]\fR\fB\fIdbname\fR\fR
78 Specifies the name of the database to be cleaned or analyzed, when
79 \fB\-a\fR/\fB\-\-all\fR
80 is not used\&. If this is not specified, the database name is read from the environment variable
81 \fBPGDATABASE\fR\&. If that is not set, the user name specified for the connection is used\&. The
84 connection string\&. If so, connection string parameters will override any conflicting command line options\&.
87 \fB\-\-disable\-page\-skipping\fR
89 Disable skipping pages based on the contents of the visibility map\&.
96 Echo the commands that
98 generates and sends to the server\&.
119 \fB\-\-force\-index\-cleanup\fR
121 Always remove index entries pointing to dead tuples\&.
124 \fB\-j \fR\fB\fInjobs\fR\fR
126 \fB\-\-jobs=\fR\fB\fInjobs\fR\fR
128 Execute the vacuum or analyze commands in parallel by running
130 commands simultaneously\&. This option may reduce the processing time but it also increases the load on the database server\&.
135 connections to the database, so make sure your
137 setting is high enough to accommodate all connections\&.
139 Note that using this mode together with the
141 (FULL) option might cause deadlock failures if certain system catalogs are processed in parallel\&.
144 \fB\-\-min\-mxid\-age \fR\fB\fImxid_age\fR\fR
146 Only execute the vacuum or analyze commands on tables with a multixact ID age of at least
147 \fImxid_age\fR\&. This setting is useful for prioritizing tables to process to prevent multixact ID wraparound (see
148 Section\ \&24.1.5.1)\&.
150 For the purposes of this option, the multixact ID age of a relation is the greatest of the ages of the main relation and its associated
152 table, if one exists\&. Since the commands issued by
154 will also process the
156 table for the relation if necessary, it does not need to be considered separately\&.
159 \fB\-\-min\-xid\-age \fR\fB\fIxid_age\fR\fR
161 Only execute the vacuum or analyze commands on tables with a transaction ID age of at least
162 \fIxid_age\fR\&. This setting is useful for prioritizing tables to process to prevent transaction ID wraparound (see
163 Section\ \&24.1.5)\&.
165 For the purposes of this option, the transaction ID age of a relation is the greatest of the ages of the main relation and its associated
167 table, if one exists\&. Since the commands issued by
169 will also process the
171 table for the relation if necessary, it does not need to be considered separately\&.
174 \fB\-\-missing\-stats\-only\fR
176 Only analyze relations that are missing statistics for a column, index expression, or extended statistics object\&. When used with
177 \fB\-\-analyze\-in\-stages\fR, this option prevents
179 from temporarily replacing existing statistics with ones generated with lower statistics targets, thus avoiding transiently worse query optimizer choices\&.
181 This option can only be used in conjunction with
182 \fB\-\-analyze\-only\fR
184 \fB\-\-analyze\-in\-stages\fR\&.
187 \fB\-\-missing\-stats\-only\fR
193 pg_statistic_ext_data, which are restricted to superusers by default\&.
196 \fB\-n \fR\fB\fIschema\fR\fR
198 \fB\-\-schema=\fR\fB\fIschema\fR\fR
200 Clean or analyze all tables in
202 only\&. Multiple schemas can be vacuumed by writing multiple
207 \fB\-N \fR\fB\fIschema\fR\fR
209 \fB\-\-exclude\-schema=\fR\fB\fIschema\fR\fR
211 Do not clean or analyze any tables in
212 \fIschema\fR\&. Multiple schemas can be excluded by writing multiple
217 \fB\-\-no\-index\-cleanup\fR
219 Do not remove index entries pointing to dead tuples\&.
222 \fB\-\-no\-process\-main\fR
224 Skip the main relation\&.
227 \fB\-\-no\-process\-toast\fR
229 Skip the TOAST table associated with the table to vacuum, if any\&.
232 \fB\-\-no\-truncate\fR
234 Do not truncate empty pages at the end of the table\&.
237 \fB\-P \fR\fB\fIparallel_workers\fR\fR
239 \fB\-\-parallel=\fR\fB\fIparallel_workers\fR\fR
241 Specify the number of parallel workers for
242 parallel vacuum\&. This allows the vacuum to leverage multiple CPUs to process indexes\&. See
250 Do not display progress messages\&.
253 \fB\-\-skip\-locked\fR
255 Skip relations that cannot be immediately locked for processing\&.
258 \fB\-t \fR\fB\fItable\fR\fR\fB [ (\fR\fB\fIcolumn\fR\fR\fB [,\&.\&.\&.]) ]\fR
260 \fB\-\-table=\fR\fB\fItable\fR\fR\fB [ (\fR\fB\fIcolumn\fR\fR\fB [,\&.\&.\&.]) ]\fR
264 only\&. Column names can be specified only in conjunction with the
267 \fB\-\-analyze\-only\fR
268 options\&. Multiple tables can be vacuumed by writing multiple
276 .nr an-no-space-flag 1
283 If you specify columns, you probably have to escape the parentheses from the shell\&. (See examples below\&.)
292 Print detailed information during processing\&.
308 Also calculate statistics for use by the optimizer\&.
313 \fB\-\-analyze\-only\fR
315 Only calculate statistics for use by the optimizer (no vacuum)\&.
318 \fB\-\-analyze\-in\-stages\fR
320 Only calculate statistics for use by the optimizer (no vacuum), like
321 \fB\-\-analyze\-only\fR\&. Run three stages of analyze; the first stage uses the lowest possible statistics target (see
322 default_statistics_target) to produce usable statistics faster, and subsequent stages build the full statistics\&.
324 This option is only useful to analyze a database that currently has no statistics or has wholly incorrect ones, such as if it is newly populated from a restored dump or by
325 \fBpg_upgrade\fR\&. Be aware that running with this option in a database with existing statistics may cause the query optimizer choices to become transiently worse due to the low statistics targets of the early stages\&.
334 command line arguments, and exit\&.
338 also accepts the following command\-line arguments for connection parameters:
340 \fB\-h \fR\fB\fIhost\fR\fR
342 \fB\-\-host=\fR\fB\fIhost\fR\fR
344 Specifies the host name of the machine on which the server is running\&. If the value begins with a slash, it is used as the directory for the Unix domain socket\&.
347 \fB\-p \fR\fB\fIport\fR\fR
349 \fB\-\-port=\fR\fB\fIport\fR\fR
351 Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections\&.
354 \fB\-U \fR\fB\fIusername\fR\fR
356 \fB\-\-username=\fR\fB\fIusername\fR\fR
358 User name to connect as\&.
363 \fB\-\-no\-password\fR
365 Never issue a password prompt\&. If the server requires password authentication and a password is not available by other means such as a
367 file, the connection attempt will fail\&. This option can be useful in batch jobs and scripts where no user is present to enter a password\&.
376 to prompt for a password before connecting to a database\&.
378 This option is never essential, since
380 will automatically prompt for a password if the server demands password authentication\&. However,
382 will waste a connection attempt finding out that the server wants a password\&. In some cases it is worth typing
384 to avoid the extra connection attempt\&.
387 \fB\-\-maintenance\-db=\fR\fB\fIdbname\fR\fR
390 \fB\-a\fR/\fB\-\-all\fR
391 is used, connect to this database to gather the list of databases to vacuum\&. If not specified, the
393 database will be used, or if that does not exist,
395 will be used\&. This can be a
396 connection string\&. If so, connection string parameters will override any conflicting command line options\&. Also, connection string parameters other than the database name itself will be re\-used when connecting to other databases\&.
408 Default connection parameters
413 Specifies whether to use color in diagnostic messages\&. Possible values are
420 This utility, like most other
422 utilities, also uses the environment variables supported by
428 In case of difficulty, see
432 for discussions of potential problems and error messages\&. The database server must be running at the targeted host\&. Also, any default connection settings and environment variables used by the
434 front\-end library will apply\&.
437 To clean the database
444 $ \fBvacuumdb test\fR
450 To clean and analyze for the optimizer a database named
457 $ \fBvacuumdb \-\-analyze bigdb\fR
463 To clean a single table
466 xyzzy, and analyze a single column
468 of the table for the optimizer:
474 $ \fBvacuumdb \-\-analyze \-\-verbose \-\-table=\*(Aqfoo(bar)\*(Aq xyzzy\fR
480 To clean all tables in the
484 schemas in a database named
491 $ \fBvacuumdb \-\-schema=\*(Aqfoo\*(Aq \-\-schema=\*(Aqbar\*(Aq xyzzy\fR