CLUSTERDB(1)
π¦ clusterdb(1) β the re-cluster glow-up β¨
okay bestie, so clusterdb is a PostgreSQL utility and honestly? it's giving maintenance era. it's the command-line bestie of the SQL command CLUSTER(7), and there is no effective difference between clustering databases via this utility and via any other method for accessing the server. literally none. same vibe, different font. π
πΈ NAME πΈ
clusterdb β cluster a PostgreSQL database, but make it a whole moment π
β SYNOPSIS β
clusterdb [connection-option...] [option...] [ --table | -t table ]...
[dbname | -a | --all]
π DESCRIPTION π
okay so clusterdb is a utility for reclustering tables in a PostgreSQL database. here's the tea π΅: it goes looking for tables that have previously been clustered, and then clusters them again on the same index that was last used. so it's not out here inventing new index choices, it's just re-running the last one. respect the canon. π
and important: tables that have never been clustered are not affected. they're minding their own business, and clusterdb leaves them alone. no cap. π«Ά
clusterdb is a wrapper around the SQL command CLUSTER(7) β that's the whole thing. there is no effective difference between clustering databases via this utility and via other methods for accessing the server. periodt.
β¨ OPTIONS β¨
clusterdb accepts the following command-line arguments:
-a,--allβ cluster all databases. all of them. every last one. π«[-d] dbname,[--dbname=]dbnameβ specifies the name of the database to be clustered, when-a/--allis not used. if you don't specify it, the database name is read from the environment variablePGDATABASE. and if that's not set either, the user name specified for the connection is used. also β plot twist βdbnamecan be a connection string, and if so, connection string parameters will override any conflicting command line options. π-e,--echoβ echo the commands thatclusterdbgenerates and sends to the server. so you can see exactly what it's saying behind your back. π«£-q,--quietβ do not display progress messages. silence. peaceful. π§ββοΈ-t table,--table=tableβ cluster table only. and bestie, you can cluster multiple tables by writing multiple-tswitches. stack 'em. π-v,--verboseβ print detailed information during processing. for the girlies who need to know everything. π-V,--versionβ print theclusterdbversion and exit. quick little flex. π-?,--helpβ show help aboutclusterdbcommand line arguments, and exit. when in doubt, ask for help. π
π¦ connection parameters π¦
clusterdb 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. and if the value begins with a slash, it's used as the directory for the Unix domain socket. sneaky but iconic. π-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. say it with your chest. π-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. so like, automation bestie. π€-W,--passwordβ forceclusterdbto 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. so in some cases it is worth typing -W to avoid the extra connection attempt. efficiency slay. β‘
--maintenance-db=dbnameβ when the-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, and 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. multitasking icon. π
π§ ENVIRONMENT π§
PGDATABASEPGHOSTPGPORTPGUSER
β default connection parameters. the classic quartet. π
PG_COLORβ specifies whether to use color in diagnostic messages. possible values arealways,autoandnever. (aesthetic diagnostics, we love to see it.) π
this utility, like most other PostgreSQL utilities, also uses the environment variables supported by libpq (see Section 32.15). iykyk. π
π 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. so like, check your connection before you come for the tool. π
π₯ 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)β the SQL original. the blueprint. π«Ά
and that's the whole page, bestie! π this one's from PostgreSQL 17.11, dated 2026, and yeah β that's the official documentation version and date doing their little sign-off at the bottom. go forth and recluster. β¨ππ¦
π¦ where this page comes from
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-160000.1.1 Β· PostgreSQL
- opensuse-leap 16.0: postgresql17 17.11-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