CLUSTERDB(1)
π NAME π
clusterdb - cluster a PostgreSQL database. (Yup bestie, this is the clusterdb(1) page from the PostgreSQL 13.23 Documentation. Tiny utility, big main-character energy fr fr.)
β¨ SYNOPSIS β¨
clusterdb [connection-option...] [--verbose | -v]
[ --table | -t table ]... [dbname]
clusterdb [connection-option...] [--verbose | -v] --all | -a
πΈ DESCRIPTION πΈ
Okay so clusterdb is a utility for reclustering tables in a PostgreSQL database. The way it works is iconic: it finds tables that have previously been clustered, and clusters them again on the same index that was last used. Tables that have never been clustered are not affected β no cap, they just sit there minding their own business.
clusterdb is a wrapper around the SQL command CLUSTER(7). There is no effective difference between clustering databases via this utility and via other methods for accessing the server. It's giving convenience wrapper, and honestly? Obsessed.
π OPTIONS π
clusterdb accepts the following command-line arguments:
π main command-line arguments
-a,--allβ cluster all databases.[-d] dbname,[--dbname=]dbnameβ specifies the name of the database to be clustered, when-a/--allis not used. If this is not specified, the database name is read from the environment variablePGDATABASE. If that is not set, the user name specified for the connection is used. Thedbnamecan be a connection string β if so, connection string parameters will override any conflicting command line options.-e,--echoβ echo the commands thatclusterdbgenerates and sends to the server.-q,--quietβ do not display progress messages.-t table,--table=tableβ clustertableonly. Multiple tables can be clustered by writing multiple-tswitches.-v,--verboseβ print detailed information during processing.-V,--versionβ print theclusterdbversion and exit.-?,--helpβ show help aboutclusterdbcommand line arguments, and exit.
clusterdb also accepts the following command-line arguments for connection parameters:
π 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.-w,--no-passwordβ never issue a password prompt. If the server requires password authentication and a password is not available by other means such as a.pgpassfile, the connection attempt will fail. This option can be useful in batch jobs and scripts where no user is present to enter a password.-W,--passwordβ forceclusterdbto prompt for a password before connecting to a database. This option is never essential, sinceclusterdbwill automatically prompt for a password if the server demands password authentication. However,clusterdbwill waste a connection attempt finding out that the server wants a password. In some cases it is worth typing-Wto avoid the extra connection attempt.--maintenance-db=dbnameβ when-a/--allis used, connect to this database to gather the list of databases to cluster. If not specified, thepostgresdatabase will be used, or if that does not exist,template1will 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.
π¦ ENVIRONMENT π¦
PGDATABASE,PGHOST,PGPORT,PGUSERβ default connection parameters.PG_COLORβ specifies whether to use color in diagnostic messages. Possible values arealways,autoandnever.
This utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 33.14).
π DIAGNOSTICS π
In case of difficulty, see CLUSTER(7) and psql(1) for discussions of potential problems and error messages. The database server must be running at the targeted host. Also, any default connection settings and environment variables used by the libpq front-end library will apply.
π 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 π
CLUSTER(7) β that's the one, bestie. Iykyk. π
okay bye bestie π β this clusterdb(1) page is from PostgreSQL 13.23, dated 2025. Slay and hydrate. π«Άβ¨
π¦ where this page comes from
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql13 13.23-160000.1.1 Β· PostgreSQL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms