CLUSTERDB(1)
๐ CLUSTERDB(1) ๐
okay so bestie, we're in the PostgreSQL 18.6 Documentation and today's main character is clusterdb โ she clusters a PostgreSQL database and she does it flawlessly. let's get into it ๐
โจ NAME โจ
clusterdb โ cluster a PostgreSQL database ๐ฆ
โจ SYNOPSIS โจ
clusterdb [connection-option...] [option...] [ --table | -t table ]...
[dbname | -a | --all]
โจ DESCRIPTION โจ
so like, clusterdb is a utility for reclustering tables in a PostgreSQL database. what it does is it goes and finds the tables that have previously been clustered, and then clusters them again on the same index that was last used. tables that have never been clustered? not affected, not invited, they stay exactly as they are ๐
and here's the tea: clusterdb is literally just a wrapper around the SQL command CLUSTER(7). there is no effective difference between clustering databases through this utility and doing it any other way of accessing the server. same energy, fr fr โจ
โจ OPTIONS โจ
clusterdb accepts the following command-line arguments, bestie ๐
-a,--allโ cluster all the databases. all of them. every single one ๐ซถ[-d] dbname,[--dbname=]dbnameโ tells it the name of the database you wanna cluster, for when-a/--allis not being used. if you don't specify it, the database name gets read from the environment variablePGDATABASE. and if that's not set either, then it just uses the user name that was specified for the connection. also! the dbname can be a connection string โ and if it is, connection string parameters will override any conflicting command line options. so watch out for that ๐-e,--echoโ echoes the commands thatclusterdbgenerates and sends to the server. so you can literally see what she's saying ๐ฃ-q,--quietโ don't display progress messages. silent but deadly, love that for her ๐คซ-t table,--table=tableโ cluster table only. you can cluster multiple tables by writing multiple-tswitches, one after another. iconic behavior ๐-v,--verboseโ print detailed information during processing. she's giving full transparency โจ-V,--versionโ print theclusterdbversion and exit. quick lil flex ๐-?,--helpโ show help aboutclusterdbcommand line arguments, and exit. your bestie always tells you how to use her ๐ซถ
๐ธ connection parameters ๐ธ
clusterdb also accepts the following command-line arguments for connection parameters:
-h host,--host=hostโ specifies the host name of the machine the server is running on. and if the value starts with a slash, it's used as the directory for the Unix domain socket. slash = socket, noted ๐-p port,--port=portโ specifies the TCP port, or the local Unix domain socket file extension, that the server is listening on for connections ๐-U username,--username=usernameโ the user name to connect as. who are you today? main character, obviously ๐-w,--no-passwordโ never issue a password prompt. if the server requires password authentication and a password isn't available by other means like a.pgpassfile, then the connection attempt will fail. this one is useful in batch jobs and scripts where there's literally no user around to type in a password ๐ฅฒ-W,--passwordโ forcesclusterdbto prompt for a password before connecting to a database.
this option is never essential, because clusterdb will automatically prompt for a password if the server demands password authentication anyway. BUT โ and this is the lowkey annoying part โ clusterdb will waste a whole connection attempt just finding out that the server wants a password. so sometimes it's worth typing -W to skip that extra connection attempt. efficiency, periodt ๐
--maintenance-db=dbnameโ when-a/--allis used, connect to this database to gather the list of databases to cluster. if you don't specify it, thepostgresdatabase will be used โ or, if that one doesn't exist,template1gets used instead. this can be a connection string, and if it is, 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. she remembers. she always remembers ๐ง
โจ ENVIRONMENT โจ
PGDATABASEPGHOSTPGPORTPGUSER
those four are your default connection parameters ๐
PG_COLORโ specifies whether to use color in diagnostic messages. the possible values arealways,autoandnever. aesthetic choices matter ๐
and also, this utility โ like most other PostgreSQL utilities โ uses the environment variables supported by libpq (see Section 32.15). the whole squad, fr fr ๐ซถ
โจ DIAGNOSTICS โจ
if you're having difficulty, go look at CLUSTER(7) and psql(1) for discussions of potential problems and error messages. also, the database server must be running at the targeted host, okay? that's non-negotiable ๐ญ and any default connection settings and environment variables used by the libpq front-end library will apply too.
โจ EXAMPLES โจ
to cluster the database test:
$ clusterdb test
to cluster a single table foo in a database named xyzzy:
$ clusterdb --table=foo xyzzy
look at her go ๐โจ
โจ SEE ALSO โจ
CLUSTER(7) โ that's the whole list, go read it bestie ๐
ngl if any of this is confusing just re-read the options section, it's literally all there ๐
okay and that's the whole page!! this was written for PostgreSQL 18.6, dated 2026, and it's the CLUSTERDB(1) page ๐
thanks for reading bestie, you ate this, periodt ๐โจ๐ฆ
๐ฆ where this page comes from
- alpine 3.23: postgresql18-doc 18.6-r0 ยท PostgreSQL
- alpine 3.24: postgresql18-doc 18.6-r0 ยท PostgreSQL
- arch rolling: postgresql-libs 18.6-4 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 43: postgresql 18.6-1.fc43 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- fedora 44: postgresql 18.6-1.fc44 ยท PostgreSQL
- nixos 26.05: postgresql 18.6
- ubuntu resolute: postgresql-client-18 18.6-0ubuntu0.26.04.1 ยท PostgreSQL
- ubuntu stonking: postgresql-client-18 18.6-3build2 ยท PostgreSQL
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms