Linux "vacuumdb" Command Line Options and Examples
garbage-collect and analyze a PostgreSQL database

vacuumdb is a utility for cleaning a PostgreSQL database. vacuumdb will also generate internal statistics used by the PostgreSQL query optimizer. vacuumdb is a wrapper around the SQL command VACUUM(7).


Usage:

vacuumdb [connection-option...] [option...] [ --table | -t table [( column [,...] )] ]... [dbname]


    vacuumdb [connection-option...] [option...] --all | -a




Command Line Options:

--all
Vacuum all databases.
vacuumdb --all ...
--dbname
Specifies the name of the database to be cleaned or analyzed. If this is not specified and -a (or --all)is not used, the database name is read from the environment variable PGDATABASE. If that is not set, theuser name specified for the connection is used.
vacuumdb --dbname ...
--echo
Echo the commands that vacuumdb generates and sends to the server.
vacuumdb --echo ...
--full
Perform “full” vacuuming.
vacuumdb --full ...
--freeze
Aggressively “freeze” tuples.
vacuumdb --freeze ...
--jobs
Execute the vacuum or analyze commands in parallel by running njobs commands simultaneously. This optionreduces the time of the processing 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 highenough to accommodate all connections.Note that using this mode together with the -f (FULL) option might cause deadlock failures if certainsystem catalogs are processed in parallel.
vacuumdb --jobs ...
--quiet
Do not display progress messages.
vacuumdb --quiet ...
--table=table
Clean or analyze table only. Column names can be specified only in conjunction with the --analyze or
vacuumdb --table=table ...
--analyze-only
TipIf you specify columns, you probably have to escape the parentheses from the shell. (See examplesbelow.)
vacuumdb --analyze-only ...
--verbose
Print detailed information during processing.
vacuumdb --verbose ...
--version
Print the vacuumdb version and exit.
vacuumdb --version ...
--analyze
Also calculate statistics for use by the optimizer.
vacuumdb --analyze ...
--analyze-in-stages
Only calculate statistics for use by the optimizer (no vacuum), like --analyze-only. Run several(currently three) stages of analyze with different configuration settings, to produce usable statisticsfaster.This option is useful to analyze a database that was newly populated from a restored dump or bypg_upgrade. This option will try to create some statistics as fast as possible, to make the databaseusable, and then produce full statistics in the subsequent stages.
vacuumdb --analyze-in-stages ...
--help
Show help about vacuumdb command line arguments, and exit.vacuumdb also accepts the following command-line arguments for connection parameters:
vacuumdb --help ...
--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.
vacuumdb --host ...
--port
Specifies the TCP port or local Unix domain socket file extension on which the server is listening forconnections.
vacuumdb --port ...
--username
User name to connect as.
vacuumdb --username ...
--no-password
Never issue a password prompt. If the server requires password authentication and a password is notavailable by other means such as a .pgpass file, the connection attempt will fail. This option can beuseful in batch jobs and scripts where no user is present to enter a password.
vacuumdb --no-password ...
--password
Force 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 serverdemands password authentication. However, vacuumdb will waste a connection attempt finding out that theserver wants a password. In some cases it is worth typing -W to avoid the extra connection attempt.
vacuumdb --password ...
--maintenance-db
Specifies the name of the database to connect to discover what other databases should be vacuumed. If notspecified, the postgres database will be used, and if that does not exist, template1 will be used.ENVIRONMENTPGDATABASEPGHOSTPGPORTPGUSERDefault connection parametersThis utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq(see Section 33.14).DIAGNOSTICSIn case of difficulty, see VACUUM(7) and psql(1) for discussions of potential problems and error messages. Thedatabase server must be running at the targeted host. Also, any default connection settings and environmentvariables used by the libpq front-end library will apply.NOTESvacuumdb might need to connect several times to the PostgreSQL server, asking for a password each time. It isconvenient to have a ~/.pgpass file in such cases. See Section 33.15 for more information.EXAMPLESTo clean the database test:$ vacuumdb testTo clean and analyze for the optimizer a database named bigdb:$ vacuumdb --analyze bigdbTo clean a single table foo in a database named xyzzy, and analyze a single column bar of the table for theoptimizer:$ vacuumdb --analyze --verbose --table='foo(bar)' xyzzy
vacuumdb --maintenance-db ...