{
    "mode": "man",
    "parameter": "clusterdb",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/clusterdb/1/json",
    "generated": "2026-06-17T13:16:31Z",
    "synopsis": "clusterdb [connection-option...] [--verbose | -v] [ --table | -t table ]...  [dbname]\nclusterdb [connection-option...] [--verbose | -v] --all | -a",
    "sections": {
        "NAME": {
            "content": "clusterdb - cluster a PostgreSQL database\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "clusterdb [connection-option...] [--verbose | -v] [ --table | -t table ]...  [dbname]\n\nclusterdb [connection-option...] [--verbose | -v] --all | -a\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "clusterdb is a utility for reclustering tables in a PostgreSQL database. It finds tables that\nhave previously been clustered, and clusters them again on the same index that was last used.\nTables that have never been clustered are not affected.\n\nclusterdb is a wrapper around the SQL command CLUSTER(7). There is no effective difference\nbetween clustering databases via this utility and via other methods for accessing the server.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "clusterdb accepts the following command-line arguments:\n",
            "subsections": [
                {
                    "name": "-a",
                    "content": "",
                    "flag": "-a"
                },
                {
                    "name": "--all",
                    "content": "Cluster all databases.\n\n[-d] dbname\n[--dbname=]dbname\nSpecifies the name of the database to be clustered, when -a/--all is not used. If this is\nnot specified, the database name is read from the environment variable PGDATABASE. If\nthat is not set, the user name specified for the connection is used. The dbname can be a\nconnection string. If so, connection string parameters will override any conflicting\ncommand line options.\n",
                    "long": "--all"
                },
                {
                    "name": "-e",
                    "content": "",
                    "flag": "-e"
                },
                {
                    "name": "--echo",
                    "content": "Echo the commands that clusterdb generates and sends to the server.\n",
                    "long": "--echo"
                },
                {
                    "name": "-q",
                    "content": "",
                    "flag": "-q"
                },
                {
                    "name": "--quiet",
                    "content": "Do not display progress messages.\n",
                    "long": "--quiet"
                },
                {
                    "name": "-t",
                    "content": "--table=table\nCluster table only. Multiple tables can be clustered by writing multiple -t switches.\n",
                    "flag": "-t"
                },
                {
                    "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 clusterdb version and exit.\n\n-?",
                    "long": "--version"
                },
                {
                    "name": "--help",
                    "content": "Show help about clusterdb command line arguments, and exit.\n\nclusterdb also accepts the following command-line arguments for connection parameters:\n",
                    "long": "--help"
                },
                {
                    "name": "-h",
                    "content": "--host=host\nSpecifies the host name of the machine on which the server is running. If the value\nbegins with a slash, it is used as the directory for the Unix domain socket.\n",
                    "flag": "-h"
                },
                {
                    "name": "-p",
                    "content": "--port=port\nSpecifies the TCP port or local Unix domain socket file extension on which the server is\nlistening for connections.\n",
                    "flag": "-p"
                },
                {
                    "name": "-U",
                    "content": "--username=username\nUser name to connect as.\n",
                    "flag": "-U"
                },
                {
                    "name": "-w",
                    "content": "",
                    "flag": "-w"
                },
                {
                    "name": "--no-password",
                    "content": "Never issue a password prompt. If the server requires password authentication and a\npassword is not available by other means such as a .pgpass file, the connection attempt\nwill fail. This option can be useful in batch jobs and scripts where no user is present\nto enter a password.\n",
                    "long": "--no-password"
                },
                {
                    "name": "-W",
                    "content": "",
                    "flag": "-W"
                },
                {
                    "name": "--password",
                    "content": "Force clusterdb to prompt for a password before connecting to a database.\n\nThis option is never essential, since clusterdb will automatically prompt for a password\nif the server demands password authentication. However, clusterdb will waste a connection\nattempt finding out that the server wants a password. In some cases it is worth typing -W\nto avoid the extra connection attempt.\n\n--maintenance-db=dbname\nWhen the -a/--all is used, connect to this database to gather the list of databases to\ncluster. If not specified, the postgres database will be used, or if that does not exist,\ntemplate1 will be used. This can be a connection string. If so, connection string\nparameters will override any conflicting command line options. Also, connection string\nparameters other than the database name itself will be re-used when connecting to other\ndatabases.\n",
                    "long": "--password"
                }
            ]
        },
        "ENVIRONMENT": {
            "content": "PGDATABASE\nPGHOST\nPGPORT\nPGUSER\nDefault connection parameters\n\nPGCOLOR\nSpecifies whether to use color in diagnostic messages. Possible values are always, auto\nand never.\n\nThis utility, like most other PostgreSQL utilities, also uses the environment variables\nsupported by libpq (see Section 34.15).\n",
            "subsections": []
        },
        "DIAGNOSTICS": {
            "content": "In case of difficulty, see CLUSTER(7) and psql(1) for discussions of potential problems and\nerror messages. The database server must be running at the targeted host. Also, any default\nconnection settings and environment variables used by the libpq front-end library will apply.\n",
            "subsections": []
        },
        "EXAMPLES": {
            "content": "To cluster the database test:\n\n$ clusterdb test\n\nTo cluster a single table foo in a database named xyzzy:\n\n$ clusterdb --table=foo xyzzy\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "CLUSTER(7)\n\n\n\nPostgreSQL 14.23                                2026                                    CLUSTERDB(1)",
            "subsections": []
        }
    },
    "summary": "clusterdb - cluster a PostgreSQL database",
    "flags": [
        {
            "flag": "-a",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--all",
            "arg": null,
            "description": "Cluster all databases. [-d] dbname [--dbname=]dbname Specifies the name of the database to be clustered, 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": "-e",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--echo",
            "arg": null,
            "description": "Echo the commands that clusterdb generates and sends to the server."
        },
        {
            "flag": "-q",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "",
            "long": "--quiet",
            "arg": null,
            "description": "Do not display progress messages."
        },
        {
            "flag": "-t",
            "long": null,
            "arg": null,
            "description": "--table=table Cluster table only. Multiple tables can be clustered by writing multiple -t switches."
        },
        {
            "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 clusterdb version and exit. -?"
        },
        {
            "flag": "",
            "long": "--help",
            "arg": null,
            "description": "Show help about clusterdb command line arguments, and exit. clusterdb also accepts the following command-line arguments for connection parameters:"
        },
        {
            "flag": "-h",
            "long": null,
            "arg": null,
            "description": "--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."
        },
        {
            "flag": "-p",
            "long": null,
            "arg": null,
            "description": "--port=port Specifies the TCP port or local Unix domain socket file extension on which the server is listening for connections."
        },
        {
            "flag": "-U",
            "long": null,
            "arg": null,
            "description": "--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 clusterdb to prompt for a password before connecting to a database. This option is never essential, since clusterdb will automatically prompt for a password if the server demands password authentication. However, clusterdb 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 cluster. 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 cluster the database test:",
        "$ clusterdb test",
        "To cluster a single table foo in a database named xyzzy:",
        "$ clusterdb --table=foo xyzzy"
    ],
    "see_also": [
        {
            "name": "CLUSTER",
            "section": "7",
            "url": "https://www.chedong.com/phpMan.php/man/CLUSTER/7/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Cluster (reorganize) a PostgreSQL database.",
        "examples": [
            {
                "description": "Cluster a specific database",
                "command": "clusterdb {{database_name}}"
            },
            {
                "description": "Cluster all databases",
                "command": "clusterdb {{-a|--all}}"
            },
            {
                "description": "Cluster a specific table in a database",
                "command": "clusterdb {{-t|--table}} {{table_name}} {{database_name}}"
            }
        ]
    }
}