VACUUMDB(1)
๐ VACUUMDB(1) โ the PostgreSQL 18.6 glow-up for your database
okay so bestie, welcome to vacuumdb, the โจiconicโจ PostgreSQL 18.6 utility that does your database's spring cleaning. this whole page is literally the manual, just with main character energy. let's go ๐
๐ธ NAME ๐ธ
vacuumdb โ garbage-collect and analyze a PostgreSQL database ๐๏ธโจ
๐ฆ SYNOPSIS ๐ฆ
vacuumdb [connection-option...] [option...]
[ -t | --table table [( column [,...] )] ]...
[dbname | -a | --all]
vacuumdb [connection-option...] [option...] [ -n | --schema schema ]...
[dbname | -a | --all]
vacuumdb [connection-option...] [option...]
[ -N | --exclude-schema schema ]... [dbname | -a | --all]
like. three whole moods. pick your vibe ๐
๐ DESCRIPTION ๐
vacuumdb is a utility for cleaning a PostgreSQL database. it will also generate the internal statistics that the PostgreSQL query optimizer uses, which is lowkey the whole reason your queries stop being embarrassing.
vacuumdb is a wrapper around the SQL command VACUUM. and no cap โ there is no effective difference between vacuuming and analyzing databases through this utility versus through any other method of accessing the server. same energy, same results, fr fr. ๐ซถ
โจ OPTIONS โจ
vacuumdb accepts the following command-line arguments:
-a,--allโ Vacuum all databases. all of them. every single one ๐--buffer-usage-limit sizeโ Specifies the Buffer Access Strategy ring buffer size for a given invocation ofvacuumdb. This size is used to calculate the number of shared buffers which will be reused as part of this strategy. SeeVACUUM(7). ๐[-d] dbname,[--dbname=]dbnameโ Specifies the name of the database to be cleaned or analyzed, when-a/--allis not used. If this is not specified, the database name is read from the environment variablePGDATABASE. If that is not set, the user name specified for the connection is used. The dbname can be a connection string. If so, connection string parameters will override any conflicting command line options. it's giving flexible ๐--disable-page-skippingโ Disable skipping pages based on the contents of the visibility map. ๐-e,--echoโ Echo the commands thatvacuumdbgenerates and sends to the server. so you can see exactly what it's up to. nosy bestie rights ๐-f,--fullโ Perform โfullโ vacuuming. the whole thing. the full send ๐ฅ-F,--freezeโ Aggressively โfreezeโ tuples. aggressive, periodt โ๏ธ--force-index-cleanupโ Always remove index entries pointing to dead tuples. no dead weight allowed ๐งน-j njobs,--jobs=njobsโ Execute the vacuum or analyze commands in parallel by running njobs commands simultaneously. This option may reduce the processing time but it also increases the load on the database server.
vacuumdb will open njobs connections to the database, so make sure your max_connections setting is high enough to accommodate all connections.
Note that using this mode together with the -f (FULL) option might cause deadlock failures if certain system catalogs are processed in parallel. ๐ be careful bestie.
--min-mxid-age mxid_ageโ Only execute the vacuum or analyze commands on tables with a multixact ID age of at least mxid_age. This setting is useful for prioritizing tables to process to prevent multixact ID wraparound (see Section 24.1.5.1).
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 TOAST table, if one exists. Since the commands issued by vacuumdb will also process the TOAST table for the relation if necessary, it does not need to be considered separately. ๐ (toast!!)
--min-xid-age xid_ageโ Only execute the vacuum or analyze commands on tables with a transaction ID age of at least xid_age. This setting is useful for prioritizing tables to process to prevent transaction ID wraparound (see Section 24.1.5).
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 TOAST table, if one exists. Since the commands issued by vacuumdb will also process the TOAST table for the relation if necessary, it does not need to be considered separately. same toast rules, different age โจ
--missing-stats-onlyโ Only analyze relations that are missing statistics for a column, index expression, or extended statistics object. When used with--analyze-in-stages, this option preventsvacuumdbfrom temporarily replacing existing statistics with ones generated with lower statistics targets, thus avoiding transiently worse query optimizer choices.
This option can only be used in conjunction with --analyze-only or --analyze-in-stages.
Note that--missing-stats-onlyrequiresSELECTprivileges onpg_statisticandpg_statistic_ext_data, which are restricted to superusers by default. ๐
-n schema,--schema=schemaโ Clean or analyze all tables in schema only. Multiple schemas can be vacuumed by writing multiple-nswitches. stack 'em ๐ธ-N schema,--exclude-schema=schemaโ Do not clean or analyze any tables in schema. Multiple schemas can be excluded by writing multiple-Nswitches. not you, not you, also not you ๐--no-index-cleanupโ Do not remove index entries pointing to dead tuples.--no-process-mainโ Skip the main relation. ๐ซ--no-process-toastโ Skip the TOAST table associated with the table to vacuum, if any.--no-truncateโ Do not truncate empty pages at the end of the table.-P parallel_workers,--parallel=parallel_workersโ Specify the number of parallel workers for parallel vacuum. This allows the vacuum to leverage multiple CPUs to process indexes. SeeVACUUM(7). multicore slay ๐ฅ-q,--quietโ Do not display progress messages. shhh ๐คซ--skip-lockedโ Skip relations that cannot be immediately locked for processing.-t table [ (column [,...]) ],--table=table [ (column [,...]) ]โ Clean or analyze table only. Column names can be specified only in conjunction with the--analyzeor--analyze-onlyoptions. Multiple tables can be vacuumed by writing multiple-tswitches.
Tip ๐ If you specify columns, you probably have to escape the parentheses from the shell. (See examples below.) your shell will absolutely eat them otherwise, bestie.
-v,--verboseโ Print detailed information during processing. tell me everything ๐ฃ๏ธ-V,--versionโ Print thevacuumdbversion and exit.-z,--analyzeโ Also calculate statistics for use by the optimizer. ๐-Z,--analyze-onlyโ Only calculate statistics for use by the optimizer (no vacuum).--analyze-in-stagesโ Only calculate statistics for use by the optimizer (no vacuum), like--analyze-only. Run three stages of analyze; the first stage uses the lowest possible statistics target (seedefault_statistics_target) to produce usable statistics faster, and subsequent stages build the full statistics.
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 pg_upgrade. 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. โ ๏ธ three-stage era, but know the risks.
-?,--helpโ Show help aboutvacuumdbcommand line arguments, and exit. ๐
vacuumdb also accepts the following command-line arguments for connection parameters:
-h host,--host=hostโ 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. ๐-p port,--port=portโ Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections.-U username,--username=usernameโ User name to connect as.-w,--no-passwordโ Never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a.pgpassfile, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password. ๐ค-W,--passwordโ Forcevacuumdbto prompt for a password before connecting to a database.
This option is never essential, since vacuumdb will automatically prompt for a password if the server demands password authentication. However, vacuumdb will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt. ๐
--maintenance-db=dbnameโ When the-a/--allis used, connect to this database to gather the list of databases to vacuum. If not specified, thepostgresdatabase will be used, or if that does not exist,template1will be used. This can be a 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. ๐
๐ฑ ENVIRONMENT ๐ฑ
PGDATABASEPGHOSTPGPORTPGUSER
Default connection parameters
PG_COLORโ Specifies whether to use color in diagnostic messages. Possible values arealways,autoandnever. ๐ (yes the diagnostics can be cute too)
This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 32.15).
๐ฉบ DIAGNOSTICS ๐ฉบ
In case of difficulty, see VACUUM(7) and psql(1) 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 libpq front-end library will apply. like. the server has to actually be up, bestie ๐ญ
๐ EXAMPLES ๐
To clean the database test:
$ vacuumdb test
To clean and analyze for the optimizer a database named bigdb:
$ vacuumdb --analyze bigdb
To clean a single table foo in a database named xyzzy, and analyze a single column bar of the table for the optimizer:
$ vacuumdb --analyze --verbose --table='foo(bar)' xyzzy
see?? the parentheses got escaped, exactly like the tip said ๐ซถ
To clean all tables in the foo and bar schemas in a database named xyzzy:
$ vacuumdb --schema='foo' --schema='bar' xyzzy
๐ SEE ALSO ๐
and that's the whole page, bestie!! ๐ this was PostgreSQL 18.6, dated 2026, and the page is VACUUMDB(1). now go forth and vacuum, you gorgeous little database gremlin ๐๐งโจ
๐ฆ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql-libs 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms