VACUUMDB(1)

πŸ“¦ version 13.23, in opensuse-leap 16.0

🧹 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/--all is not used. if you don't specify it, the database name is read from the environment variable PGDATABASE. 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 that vacuumdb generates 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. see VACUUM(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 --analyze or --analyze-only options. multiple tables can be vacuumed by writing multiple -t switches. 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 the vacuumdb version 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 about vacuumdb command 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 .pgpass 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 πŸ€–
  • -W, --password β€” forces vacuumdb to 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/--all is used, connect to this database to gather the list of databases to vacuum. if not specified, the postgres database will be used, or if that does not exist, template1 will 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 🌈

  • PGDATABASE
  • PGHOST
  • PGPORT
  • PGUSER

default connection parameters ✨

  • PG_COLOR β€” specifies whether to use color in diagnostic messages. possible values are always, auto and never 🎨

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 πŸ‘€

VACUUM(7)


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