VACUUMDB(1)
π§Ή VACUUMDB β¨
okay bestie, welcome to the vacuumdb page β yes it's a PostgreSQL 13.23 manual page, and yes it's actually kind of iconic once you get past the name. it's giving "glow-up for your database" π
π NAME π
vacuumdb β garbage-collect and analyze a PostgreSQL database. literally the cleanup crew of the Postgres world π§Ήβ¨
πΈ SYNOPSIS πΈ
vacuumdb [connection-option...] [option...]
[ -t | --table table [( column [,...] )] ]... [dbname]
vacuumdb [connection-option...] [option...] -a | --all
π¦ DESCRIPTION π¦
sooo vacuumdb is a utility for cleaning a PostgreSQL database π§Ό. and not just cleaning β it's also gonna generate the internal statistics that the PostgreSQL query optimizer uses. so it's like, cleaning and doing your stats homework. main character energy fr fr π
vacuumdb is a wrapper around the SQL command VACUUM(7). and here's the thing β there is no effective difference between vacuuming and analyzing databases via this utility versus via other methods for accessing the server. same energy, different fit π
π OPTIONS π
vacuumdb accepts the following command-line arguments:
-a,--allβ vacuum all the databases. all of them. every last one π«Ά[-d] dbname,[--dbname=]dbnameβ tells it the name of the database to be cleaned or analyzed, when-a/--allis not used. if you don't specify it, the database name is read from the environment variablePGDATABASE. and if that's not set, the user name specified for the connection is used. also!! the dbname can be a connection string β and if it is, connection string parameters will override any conflicting command line options π--disable-page-skippingβ disables skipping pages based on the contents of the visibility map.
π Note: this option is only available for servers running PostgreSQL 9.6 and later.
-e,--echoβ echoes the commands thatvacuumdbgenerates and sends to the server. so you can see exactly what it's saying behind your back π£οΈ-f,--fullβ performs "full" vacuuming.-F,--freezeβ aggressively "freeze" tuples. aggressive. like that one friend who's a little too competitive at board games π₯Ά-j njobs,--jobs=njobsβ executes 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. tradeoffs, bestie π
vacuumdb will open njobs connections to the database, so make sure your max_connections setting is high enough to accommodate all connections. do not skip this. fr fr.
also note: using this mode together with the -f (FULL) option might cause deadlock failures if certain system catalogs are processed in parallel. π
--min-mxid-age mxid_ageβ only executes 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. and 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 π
π Note: this option is only available for servers running PostgreSQL 9.6 and later.
--min-xid-age xid_ageβ only executes 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. and 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 π
π Note: this option is only available for servers running PostgreSQL 9.6 and later.
-P parallel_workers,--parallel=parallel_workersβ specifies the number of parallel workers for parallel vacuum. this allows the vacuum to leverage multiple CPUs to process indexes. seeVACUUM(7). it's giving multitasking queen π§
π Note: this option is only available for servers running PostgreSQL 13 and later.
-q,--quietβ do not display progress messages. silence. peace. no thoughts head empty π«§--skip-lockedβ skips relations that cannot be immediately locked for processing. if it's locked, leave it alone, it's not ready πͺ
π Note: this option is only available for servers running PostgreSQL 12 and later.
-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. stack 'em up π
π‘ Tip: if you specify columns, you probably have to escape the parentheses from the shell. (see examples below.)
-v,--verboseβ prints detailed information during processing. the yapper option π£οΈπ¬-V,--versionβ prints thevacuumdbversion and exits.-z,--analyzeβ also calculates statistics for use by the optimizer π-Z,--analyze-onlyβ only calculates statistics for use by the optimizer (no vacuum).--analyze-in-stagesβ only calculates statistics for use by the optimizer (no vacuum), like--analyze-only. runs several (currently three) stages of analyze with different configuration settings, to produce usable statistics faster β‘
this option is useful to analyze a database that was newly populated from a restored dump or by pg_upgrade. and it will try to create some statistics as fast as possible, to make the database usable, and then produce full statistics in the subsequent stages. love a phased rollout honestly πΈ
-?,--helpβ shows help aboutvacuumdbcommand line arguments, and exits π«Ά
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β forcesvacuumdbto 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. and in some cases it is worth typing -W to avoid the extra connection attempt. efficiency, babe π
--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 β and 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. recycling, we love to see it β»οΈπ
π ENVIRONMENT π
PGDATABASEPGHOSTPGPORTPGUSER
default connection parameters β¨
PG_COLORβ specifies whether to use color in diagnostic messages. possible values arealways,autoandneverπ¨
this utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 33.14).
π©Ί 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 β it can't help you if it's not even awake bestie π΄. also, any default connection settings and environment variables used by the libpq front-end library will apply.
ποΈ NOTES ποΈ
vacuumdb might need to connect several times to the PostgreSQL server, asking for a password each time π. it is convenient to have a ~/.pgpass file in such cases. see Section 33.15 for more information. save yourself the repetitive typing, you deserve it π«Ά
π 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 are escaped like the tip said β told you so π β¨
π SEE ALSO π
and that's the whole page bestie ππ this was VACUUMDB(1) from the PostgreSQL 13.23 documentation, dated 2025 β go forth and vacuum slay β¨π§Ήπ
π¦ where this page comes from
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms