{
    "mode": "info",
    "parameter": "VACUUMDB",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/VACUUMDB/json",
    "generated": "2026-07-05T23:23:02Z",
    "synopsis": "vacuumdb [connection-option...] [option...]\n[ -t | --table table [( column [,...] )] ]...  [dbname]\nvacuumdb [connection-option...] [option...] -a | --all",
    "sections": {
        "NAME": {
            "content": "vacuumdb - garbage-collect and analyze a PostgreSQL database\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "vacuumdb [connection-option...] [option...]\n[ -t | --table table [( column [,...] )] ]...  [dbname]\n\nvacuumdb [connection-option...] [option...] -a | --all\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "vacuumdb is a utility for cleaning a PostgreSQL database.  vacuumdb\nwill also generate internal statistics used by the PostgreSQL query\noptimizer.\n\nvacuumdb is a wrapper around the SQL command VACUUM. There is no\neffective difference between vacuuming and analyzing databases via this\nutility and via other methods for accessing the server.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "vacuumdb accepts the following command-line arguments:\n",
            "subsections": [
                {
                    "name": "-a",
                    "content": "",
                    "flag": "-a"
                },
                {
                    "name": "--all",
                    "content": "Vacuum all databases.\n\n[-d] dbname\n[--dbname=]dbname\nSpecifies the name of the database to be cleaned or analyzed, when\n-a/--all is not used. If this is not specified, the database name\nis read from the environment variable PGDATABASE. If that is not\nset, the user name specified for the connection is used. The dbname\ncan be a connection string. If so, connection string parameters\nwill override any conflicting command line options.\n",
                    "long": "--all"
                },
                {
                    "name": "--disable-page-skipping",
                    "content": "Disable skipping pages based on the contents of the visibility map.\n\nNote\nThis option is only available for servers running PostgreSQL\n9.6 and later.\n",
                    "long": "--disable-page-skipping"
                },
                {
                    "name": "-e",
                    "content": "",
                    "flag": "-e"
                },
                {
                    "name": "--echo",
                    "content": "Echo the commands that vacuumdb generates and sends to the server.\n",
                    "long": "--echo"
                },
                {
                    "name": "-f",
                    "content": "",
                    "flag": "-f"
                },
                {
                    "name": "--full",
                    "content": "Perform \"full\" vacuuming.\n",
                    "long": "--full"
                },
                {
                    "name": "-F",
                    "content": "",
                    "flag": "-F"
                },
                {
                    "name": "--freeze",
                    "content": "Aggressively \"freeze\" tuples.\n",
                    "long": "--freeze"
                },
                {
                    "name": "--force-index-cleanup",
                    "content": "Always remove index entries pointing to dead tuples.\n\nNote\nThis option is only available for servers running PostgreSQL 12\nand later.\n\n-j njobs\n--jobs=njobs\nExecute the vacuum or analyze commands in parallel by running njobs\ncommands simultaneously. This option may reduce the processing time\nbut it also increases the load on the database server.\n\nvacuumdb will open njobs connections to the database, so make sure\nyour maxconnections setting is high enough to accommodate all\nconnections.\n\nNote that using this mode together with the -f (FULL) option might\ncause deadlock failures if certain system catalogs are processed in\nparallel.\n\n--min-mxid-age mxidage\nOnly execute the vacuum or analyze commands on tables with a\nmultixact ID age of at least mxidage. This setting is useful for\nprioritizing tables to process to prevent multixact ID wraparound\n(see Section 25.1.5.1).\n\nFor the purposes of this option, the multixact ID age of a relation\nis the greatest of the ages of the main relation and its associated\nTOAST table, if one exists. Since the commands issued by vacuumdb\nwill also process the TOAST table for the relation if necessary, it\ndoes not need to be considered separately.\n\nNote\nThis option is only available for servers running PostgreSQL\n9.6 and later.\n\n--min-xid-age xidage\nOnly execute the vacuum or analyze commands on tables with a\ntransaction ID age of at least xidage. This setting is useful for\nprioritizing tables to process to prevent transaction ID wraparound\n(see Section 25.1.5).\n\nFor the purposes of this option, the transaction ID age of a\nrelation is the greatest of the ages of the main relation and its\nassociated TOAST table, if one exists. Since the commands issued by\nvacuumdb will also process the TOAST table for the relation if\nnecessary, it does not need to be considered separately.\n\nNote\nThis option is only available for servers running PostgreSQL\n9.6 and later.\n",
                    "long": "--force-index-cleanup"
                },
                {
                    "name": "--no-index-cleanup",
                    "content": "Do not remove index entries pointing to dead tuples.\n\nNote\nThis option is only available for servers running PostgreSQL 12\nand later.\n",
                    "long": "--no-index-cleanup"
                },
                {
                    "name": "--no-process-toast",
                    "content": "Skip the TOAST table associated with the table to vacuum, if any.\n\nNote\nThis option is only available for servers running PostgreSQL 14\nand later.\n",
                    "long": "--no-process-toast"
                },
                {
                    "name": "--no-truncate",
                    "content": "Do not truncate empty pages at the end of the table.\n\nNote\nThis option is only available for servers running PostgreSQL 12\nand later.\n\n-P parallelworkers\n--parallel=parallelworkers\nSpecify the number of parallel workers for parallel vacuum. This\nallows the vacuum to leverage multiple CPUs to process indexes. See\nVACUUM(7).\n\nNote\nThis option is only available for servers running PostgreSQL 13\nand later.\n",
                    "long": "--no-truncate"
                },
                {
                    "name": "-q",
                    "content": "",
                    "flag": "-q"
                },
                {
                    "name": "--quiet",
                    "content": "Do not display progress messages.\n",
                    "long": "--quiet"
                },
                {
                    "name": "--skip-locked",
                    "content": "Skip relations that cannot be immediately locked for processing.\n\nNote\nThis option is only available for servers running PostgreSQL 12\nand later.\n\n-t table [ (column [,...]) ]\n--table=table [ (column [,...]) ]\nClean or analyze table only. Column names can be specified only in\nconjunction with the --analyze or --analyze-only options. Multiple\ntables can be vacuumed by writing multiple -t switches.\n\nTip\nIf you specify columns, you probably have to escape the\nparentheses from the shell. (See examples below.)\n",
                    "long": "--skip-locked"
                },
                {
                    "name": "-v",
                    "content": "",
                    "flag": "-v"
                },
                {
                    "name": "--verbose",
                    "content": "Print detailed information during processing.\n",
                    "long": "--verbose"
                },
                {
                    "name": "-V",
                    "content": "",
                    "flag": "-V"
                },
                {
                    "name": "--version",
                    "content": "Print the vacuumdb version and exit.\n",
                    "long": "--version"
                },
                {
                    "name": "-z",
                    "content": "",
                    "flag": "-z"
                },
                {
                    "name": "--analyze",
                    "content": "Also calculate statistics for use by the optimizer.\n",
                    "long": "--analyze"
                },
                {
                    "name": "-Z",
                    "content": "",
                    "flag": "-Z"
                },
                {
                    "name": "--analyze-only",
                    "content": "Only calculate statistics for use by the optimizer (no vacuum).\n",
                    "long": "--analyze-only"
                },
                {
                    "name": "--analyze-in-stages",
                    "content": "Only calculate statistics for use by the optimizer (no vacuum),\nlike --analyze-only. Run several (currently three) stages of\nanalyze with different configuration settings, to produce usable\nstatistics faster.\n\nThis option is useful to analyze a database that was newly\npopulated from a restored dump or by pgupgrade. This option will\ntry to create some statistics as fast as possible, to make the\ndatabase usable, and then produce full statistics in the subsequent\nstages.\n\n-?",
                    "long": "--analyze-in-stages"
                },
                {
                    "name": "--help",
                    "content": "Show help about vacuumdb command line arguments, and exit.\n\nvacuumdb also accepts the following command-line arguments for\nconnection parameters:\n\n-h host\n--host=host\nSpecifies the host name of the machine on which the server is\nrunning. If the value begins with a slash, it is used as the\ndirectory for the Unix domain socket.\n\n-p port\n--port=port\nSpecifies the TCP port or local Unix domain socket file extension\non which the server is listening for connections.\n\n-U username\n--username=username\nUser name to connect as.\n",
                    "long": "--help"
                },
                {
                    "name": "-w",
                    "content": "",
                    "flag": "-w"
                },
                {
                    "name": "--no-password",
                    "content": "Never issue a password prompt. If the server requires password\nauthentication and a password is not available by other means such\nas a .pgpass file, the connection attempt will fail. This option\ncan be useful in batch jobs and scripts where no user is present to\nenter a password.\n",
                    "long": "--no-password"
                },
                {
                    "name": "-W",
                    "content": "",
                    "flag": "-W"
                },
                {
                    "name": "--password",
                    "content": "Force vacuumdb to prompt for a password before connecting to a\ndatabase.\n\nThis option is never essential, since vacuumdb will automatically\nprompt for a password if the server demands password\nauthentication. However, vacuumdb will waste a connection attempt\nfinding out that the server wants a password. In some cases it is\nworth typing -W to avoid the extra connection attempt.\n\n--maintenance-db=dbname\nWhen the -a/--all is used, connect to this database to gather the\nlist of databases to vacuum. If not specified, the postgres\ndatabase will be used, or if that does not exist, template1 will be\nused. This can be a connection string. If so, connection string\nparameters will override any conflicting command line options.\nAlso, connection string parameters other than the database name\nitself will be re-used when connecting to other databases.\n",
                    "long": "--password"
                }
            ]
        },
        "ENVIRONMENT": {
            "content": "PGDATABASE\nPGHOST\nPGPORT\nPGUSER\nDefault connection parameters\n\nPGCOLOR\nSpecifies whether to use color in diagnostic messages. Possible\nvalues are always, auto and never.\n\nThis utility, like most other PostgreSQL utilities, also uses the\nenvironment variables supported by libpq (see Section 34.15).\n",
            "subsections": []
        },
        "DIAGNOSTICS": {
            "content": "In case of difficulty, see VACUUM(7) and psql(1) for discussions of\npotential problems and error messages. The database server must be\nrunning at the targeted host. Also, any default connection settings and\nenvironment variables used by the libpq front-end library will apply.\n",
            "subsections": []
        },
        "NOTES": {
            "content": "vacuumdb might need to connect several times to the PostgreSQL server,\nasking for a password each time. It is convenient to have a ~/.pgpass\nfile in such cases. See Section 34.16 for more information.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "To clean the database test:\n\n$ vacuumdb test\n\nTo clean and analyze for the optimizer a database named bigdb:\n\n$ vacuumdb --analyze bigdb\n\nTo clean a single table foo in a database named xyzzy, and analyze a\nsingle column bar of the table for the optimizer:\n\n$ vacuumdb --analyze --verbose --table='foo(bar)' xyzzy\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "VACUUM(7)\n\nPostgreSQL 14.23                     2026                          VACUUMDB(1)",
            "subsections": []
        }
    },
    "summary": "vacuumdb - garbage-collect and analyze a PostgreSQL database",
    "flags": [
        {
            "flag": "-a",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--all",
            "arg": null,
            "description": "Vacuum all databases. [-d] dbname [--dbname=]dbname Specifies the name of the database to be cleaned or analyzed, when -a/--all is not used. If this is not specified, the database name is read from the environment variable PGDATABASE. If that is not set, the user name specified for the connection is used. The dbname can be a connection string. If so, connection string parameters will override any conflicting command line options."
        },
        {
            "flag": "",
            "long": "--disable-page-skipping",
            "arg": null,
            "description": "Disable skipping pages based on the contents of the visibility map. Note This option is only available for servers running PostgreSQL 9.6 and later."
        },
        {
            "flag": "-e",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--echo",
            "arg": null,
            "description": "Echo the commands that vacuumdb generates and sends to the server."
        },
        {
            "flag": "-f",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--full",
            "arg": null,
            "description": "Perform \"full\" vacuuming."
        },
        {
            "flag": "-F",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--freeze",
            "arg": null,
            "description": "Aggressively \"freeze\" tuples."
        },
        {
            "flag": "",
            "long": "--force-index-cleanup",
            "arg": null,
            "description": "Always remove index entries pointing to dead tuples. Note This option is only available for servers running PostgreSQL 12 and later. -j njobs --jobs=njobs Execute 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. vacuumdb will open njobs connections to the database, so make sure your maxconnections setting is high enough to accommodate all connections. Note that using this mode together with the -f (FULL) option might cause deadlock failures if certain system catalogs are processed in parallel. --min-mxid-age mxidage Only execute the vacuum or analyze commands on tables with a multixact ID age of at least mxidage. This setting is useful for prioritizing tables to process to prevent multixact ID wraparound (see Section 25.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. 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 xidage Only execute the vacuum or analyze commands on tables with a transaction ID age of at least xidage. This setting is useful for prioritizing tables to process to prevent transaction ID wraparound (see Section 25.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. 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."
        },
        {
            "flag": "",
            "long": "--no-index-cleanup",
            "arg": null,
            "description": "Do not remove index entries pointing to dead tuples. Note This option is only available for servers running PostgreSQL 12 and later."
        },
        {
            "flag": "",
            "long": "--no-process-toast",
            "arg": null,
            "description": "Skip the TOAST table associated with the table to vacuum, if any. Note This option is only available for servers running PostgreSQL 14 and later."
        },
        {
            "flag": "",
            "long": "--no-truncate",
            "arg": null,
            "description": "Do not truncate empty pages at the end of the table. Note This option is only available for servers running PostgreSQL 12 and later. -P parallelworkers --parallel=parallelworkers Specify the number of parallel workers for parallel vacuum. This allows the vacuum to leverage multiple CPUs to process indexes. See VACUUM(7). Note This option is only available for servers running PostgreSQL 13 and later."
        },
        {
            "flag": "-q",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--quiet",
            "arg": null,
            "description": "Do not display progress messages."
        },
        {
            "flag": "",
            "long": "--skip-locked",
            "arg": null,
            "description": "Skip relations that cannot be immediately locked for processing. 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. Tip If you specify columns, you probably have to escape the parentheses from the shell. (See examples below.)"
        },
        {
            "flag": "-v",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--verbose",
            "arg": null,
            "description": "Print detailed information during processing."
        },
        {
            "flag": "-V",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--version",
            "arg": null,
            "description": "Print the vacuumdb version and exit."
        },
        {
            "flag": "-z",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--analyze",
            "arg": null,
            "description": "Also calculate statistics for use by the optimizer."
        },
        {
            "flag": "-Z",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--analyze-only",
            "arg": null,
            "description": "Only calculate statistics for use by the optimizer (no vacuum)."
        },
        {
            "flag": "",
            "long": "--analyze-in-stages",
            "arg": null,
            "description": "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 statistics faster. This option is useful to analyze a database that was newly populated from a restored dump or by pgupgrade. This option will try to create some statistics as fast as possible, to make the database usable, and then produce full statistics in the subsequent stages. -?"
        },
        {
            "flag": "",
            "long": "--help",
            "arg": null,
            "description": "Show help about vacuumdb command line arguments, and exit. 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."
        },
        {
            "flag": "-w",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--no-password",
            "arg": null,
            "description": "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."
        },
        {
            "flag": "-W",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--password",
            "arg": null,
            "description": "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 server demands password authentication. However, vacuumdb will waste a connection attempt finding out that the server wants a password. In some cases it is worth typing -W to avoid the extra connection attempt. --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. 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."
        }
    ],
    "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_also": [
        {
            "name": "VACUUM",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/VACUUM/7/json"
        }
    ]
}