vacuumdb
A core utility for vacuuming and analyzing PostgreSQL
vacuumdb
is a core utility for vacuuming and analyzing PostgreSQL.
vacuumdb
was added in PostgreSQL 7.0.
Usage
vacuumdb
is effectively a command-line wrapper around the VACUUM
and ANALYZE
commands, with additional convenience functionality for:
- running
ANALYZE
in incremental stages (--analyze-in-stages
option) - vacuuming all databases in a single pass (
--all
option)
vacuumdb --all option
Somewhat counterintuitively, vacuumdb
rejects the -d
/--dbname
option when --all
is specified:
$ vacuumdb --all --analyze-in-stages -d 'host=node1 port=5433' vacuumdb: error: cannot vacuum all databases and a specific one at the same time
In this case use the --maintenance-d
b option to provide an explicit database name or conninfo string.
Source code
The vacuumdb
source code is located at src/bin/scripts/vacuumdb.c.
Change history
- PostgreSQL 16
- options
--schema
and--exclude-schema
added (commit 7781f4e3)
- options
- PostgreSQL 14
- PostgreSQL 13
- option
--parallel
added (commit 47bc9ced)
- option
- PostgreSQL 12
- PostgreSQL 9.5
- option
-j
/--jobs
for parallel processing added (commit a1792320)
- option
- PostgreSQL 9.4
- option
--analyze-in-stages
added (commit c92c3d50)
- option
- PostgreSQL 9.3
- multiple
-t
/--table
arguments supported (commit f3af5344)
- multiple
- PostgreSQL 9.2
--maintenance-db
option added (commit 68281e00)
- PostgreSQL 9.0
- option
--analyze-only
added (commit 3ccb97b2)
- option
- PostgreSQL 8.4
- PostgreSQL 8.3
- Ctrl-C interrupt handler added (commit 6e09df9d)
- PostgreSQL 7.4
- converted from a shell script into a C program (commit f374a9da)
- PostgreSQL 7.3
- support for identifiers containing spaces added (commit 5804a7ce)
- PostgreSQL 7.0
- added (commit 240e4c98)
Examples
$ vacuumdb --all --analyze-in-stages vacuumdb: processing database "contentdb": Generating minimal optimizer statistics (1 target) vacuumdb: processing database "postgres": Generating minimal optimizer statistics (1 target) vacuumdb: processing database "template1": Generating minimal optimizer statistics (1 target) vacuumdb: processing database "contentdb": Generating medium optimizer statistics (10 targets) vacuumdb: processing database "postgres": Generating medium optimizer statistics (10 targets) vacuumdb: processing database "template1": Generating medium optimizer statistics (10 targets) vacuumdb: processing database "contentdb": Generating default (full) optimizer statistics vacuumdb: processing database "postgres": Generating default (full) optimizer statistics vacuumdb: processing database "template1": Generating default (full) optimizer statistics
References
- PostgreSQL documentation: vacuumdb