As with many of the database management SQL commands, the VACUUM command has a
command-line executable wrapper called
script provides one
significant added function to the normal use of the VACUUM SQL statement, in that you can
instruct it to perform a VACUUM on each PostgreSQL database on your system.
Additionally, since it accepts connection parameters on how to connect to PostgreSQL, you may use
remotely (i.e., without having to first connect to the machine via a terminal client, and
from the remote machine). This is provided that
your authentication scheme in PostgreSQL's
file is configured for outside access (see
Chapter 8 for more information on this).
Here is the syntax for
both single-dashed and GNU-style double-dashed arguments from the command line. The only required option is the
(unless you specify
), which describes the database to be cleaned and
parameters describe which mode the VACUUM
command should be invoked in. The following are the available options for the
, - -host=
Specifies that you are connected to
, rather than the localhost. Use this option when vacuuming a remote database.
, - -port=
Specifies that the database connection is made on port
, rather than the
default port (usually 5432, though it may have been configured differently when PostgreSQL was
compiled, by the
, - -username=
Specifies that the username
is the user who connects to PostgreSQL
(rather than the name of the system user executing
- -W, - -password
Accepts no parameters, and causes a password prompt, which occurs automatically if the
file on the target server is configured not to
the requesting host.
, - -dbname=
Explicitly specifies the name of the database to perform the VACUUM
statement on. This option is mutually exclusive to the
- -a, - -all
Applies the VACUUM command, with specified options, to all databases
in the system catalog.
- -z, - -analyze
Equivalent to the ANALYZE keyword for the
VACUUM SQL command. Updates stored statistics about the data allocation between
columns, which are used by the query optimizer to help guide internal query planning.
- -t '
[, ...] ) ]', - -table='
[, ...] ) ]'
Targets a specific table
within that table) to be affected. The
option is required to describe specific columns.
- -v, - -verbose
Equivalent to the VERBOSE keyword for the VACUUM
SQL command. Causes a detailed internal report of the processing performed to be displayed.
- -e, - -echo
Accepts no parameters, and causes the query sent to PostgreSQL to be displayed to the screen as it is
- -q, - -quiet
Accepts no parameters, and causes no output to be sent to
(though any errors will
still be sent to
Example 9-16 demonstrates the use of the
the Book Town server. The
flag specifies that the connection should use the
manager user to connect, while the
flag causes all databases in the system
catalog to be affected in sequence.
Example 9-16. Using vacuumdb on all databases
[[email protected] ~]$
vacuumdb -U manager - -all
As mentioned, because of the connectivity options available to the
script, it can be
easily executed from a remote server. Example 9-17 shows a similar process to the
command used in Example 9-16, but with the addition of the
specify a remote server named
. Example 9-17 also targets the booktown database specifically, rather than
Example 9-17. Using vacuumdb on a remote database
[[email protected] ~]$
vacuumdb -h booktown.commandprompt.com -U manager booktown