4 vacuumdb — garbage-collect and analyze a PostgreSQL database
8 vacuumdb [connection-option...] [option...] [ -t | --table table [(
9 column [,...] )] ] ... [ dbname | -a | --all ]
11 vacuumdb [connection-option...] [option...] [ -n | --schema schema ]
12 ... [ dbname | -a | --all ]
14 vacuumdb [connection-option...] [option...] [ -N | --exclude-schema
15 schema ] ... [ dbname | -a | --all ]
19 vacuumdb is a utility for cleaning a PostgreSQL database. vacuumdb will
20 also generate internal statistics used by the PostgreSQL query
23 vacuumdb is a wrapper around the SQL command VACUUM. There is no
24 effective difference between vacuuming and analyzing databases via this
25 utility and via other methods for accessing the server.
29 vacuumdb accepts the following command-line arguments:
35 --buffer-usage-limit size
36 Specifies the Buffer Access Strategy ring buffer size for a
37 given invocation of vacuumdb. This size is used to calculate the
38 number of shared buffers which will be reused as part of this
43 Specifies the name of the database to be cleaned or analyzed,
44 when -a/--all is not used. If this is not specified, the
45 database name is read from the environment variable PGDATABASE.
46 If that is not set, the user name specified for the connection
47 is used. The dbname can be a connection string. If so,
48 connection string parameters will override any conflicting
51 --disable-page-skipping
52 Disable skipping pages based on the contents of the visibility
57 Echo the commands that vacuumdb generates and sends to the
62 Perform “full” vacuuming.
66 Aggressively “freeze” tuples.
69 Always remove index entries pointing to dead tuples.
73 Execute the vacuum or analyze commands in parallel by running
74 njobs commands simultaneously. This option may reduce the
75 processing time but it also increases the load on the database
78 vacuumdb will open njobs connections to the database, so make
79 sure your max_connections setting is high enough to accommodate
82 Note that using this mode together with the -f (FULL) option
83 might cause deadlock failures if certain system catalogs are
84 processed in parallel.
86 --min-mxid-age mxid_age
87 Only execute the vacuum or analyze commands on tables with a
88 multixact ID age of at least mxid_age. This setting is useful
89 for prioritizing tables to process to prevent multixact ID
90 wraparound (see Section 24.1.5.1).
92 For the purposes of this option, the multixact ID age of a
93 relation is the greatest of the ages of the main relation and
94 its associated TOAST table, if one exists. Since the commands
95 issued by vacuumdb will also process the TOAST table for the
96 relation if necessary, it does not need to be considered
100 Only execute the vacuum or analyze commands on tables with a
101 transaction ID age of at least xid_age. This setting is useful
102 for prioritizing tables to process to prevent transaction ID
103 wraparound (see Section 24.1.5).
105 For the purposes of this option, the transaction ID age of a
106 relation is the greatest of the ages of the main relation and
107 its associated TOAST table, if one exists. Since the commands
108 issued by vacuumdb will also process the TOAST table for the
109 relation if necessary, it does not need to be considered
113 Only analyze relations that are missing statistics for a column,
114 index expression, or extended statistics object. When used with
115 --analyze-in-stages, this option prevents vacuumdb from
116 temporarily replacing existing statistics with ones generated
117 with lower statistics targets, thus avoiding transiently worse
118 query optimizer choices.
120 This option can only be used in conjunction with --analyze-only
121 or --analyze-in-stages.
123 Note that --missing-stats-only requires SELECT privileges on
124 pg_statistic and pg_statistic_ext_data, which are restricted to
125 superusers by default.
129 Clean or analyze all tables in schema only. Multiple schemas can
130 be vacuumed by writing multiple -n switches.
133 --exclude-schema=schema
134 Do not clean or analyze any tables in schema. Multiple schemas
135 can be excluded by writing multiple -N switches.
138 Do not remove index entries pointing to dead tuples.
141 Skip the main relation.
144 Skip the TOAST table associated with the table to vacuum, if
148 Do not truncate empty pages at the end of the table.
151 --parallel=parallel_workers
152 Specify the number of parallel workers for parallel vacuum. This
153 allows the vacuum to leverage multiple CPUs to process indexes.
158 Do not display progress messages.
161 Skip relations that cannot be immediately locked for processing.
163 -t table [ (column [,...]) ]
164 --table=table [ (column [,...]) ]
165 Clean or analyze table only. Column names can be specified only
166 in conjunction with the --analyze or --analyze-only options.
167 Multiple tables can be vacuumed by writing multiple -t switches.
171 If you specify columns, you probably have to escape the
172 parentheses from the shell. (See examples below.)
176 Print detailed information during processing.
180 Print the vacuumdb version and exit.
184 Also calculate statistics for use by the optimizer.
188 Only calculate statistics for use by the optimizer (no vacuum).
191 Only calculate statistics for use by the optimizer (no vacuum),
192 like --analyze-only. Run three stages of analyze; the first
193 stage uses the lowest possible statistics target (see
194 default_statistics_target) to produce usable statistics faster,
195 and subsequent stages build the full statistics.
197 This option is only useful to analyze a database that currently
198 has no statistics or has wholly incorrect ones, such as if it is
199 newly populated from a restored dump or by pg_upgrade. Be aware
200 that running with this option in a database with existing
201 statistics may cause the query optimizer choices to become
202 transiently worse due to the low statistics targets of the early
207 Show help about vacuumdb command line arguments, and exit.
209 vacuumdb also accepts the following command-line arguments for
210 connection parameters:
214 Specifies the host name of the machine on which the server is
215 running. If the value begins with a slash, it is used as the
216 directory for the Unix domain socket.
220 Specifies the TCP port or local Unix domain socket file
221 extension on which the server is listening for connections.
225 User name to connect as.
229 Never issue a password prompt. If the server requires password
230 authentication and a password is not available by other means
231 such as a .pgpass file, the connection attempt will fail. This
232 option can be useful in batch jobs and scripts where no user is
233 present to enter a password.
237 Force vacuumdb to prompt for a password before connecting to a
240 This option is never essential, since vacuumdb will
241 automatically prompt for a password if the server demands
242 password authentication. However, vacuumdb will waste a
243 connection attempt finding out that the server wants a password.
244 In some cases it is worth typing -W to avoid the extra
247 --maintenance-db=dbname
248 When the -a/--all is used, connect to this database to gather
249 the list of databases to vacuum. If not specified, the postgres
250 database will be used, or if that does not exist, template1 will
251 be used. This can be a connection string. If so, connection
252 string parameters will override any conflicting command line
253 options. Also, connection string parameters other than the
254 database name itself will be re-used when connecting to other
263 Default connection parameters
266 Specifies whether to use color in diagnostic messages. Possible
267 values are always, auto and never.
269 This utility, like most other PostgreSQL utilities, also uses the
270 environment variables supported by libpq (see Section 32.15).
274 In case of difficulty, see VACUUM and psql for discussions of potential
275 problems and error messages. The database server must be running at the
276 targeted host. Also, any default connection settings and environment
277 variables used by the libpq front-end library will apply.
281 To clean the database test:
284 To clean and analyze for the optimizer a database named bigdb:
285 $ vacuumdb --analyze bigdb
287 To clean a single table foo in a database named xyzzy, and analyze a
288 single column bar of the table for the optimizer:
289 $ vacuumdb --analyze --verbose --table='foo(bar)' xyzzy
291 To clean all tables in the foo and bar schemas in a database named
293 $ vacuumdb --schema='foo' --schema='bar' xyzzy