CLUSTERDB(1)

πŸ“¦ version 17.11, in opensuse-leap 16.0

πŸ¦‹ 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/--all is not used. if you don't specify it, the database name is read from the environment variable PGDATABASE. and if that's not set either, the user name specified for the connection is used. also β€” plot twist β€” dbname can be a connection string, and if so, connection string parameters will override any conflicting command line options. πŸ‘‘
  • -e, --echo β€” echo the commands that clusterdb generates 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 -t switches. stack 'em. πŸŽ€
  • -v, --verbose β€” print detailed information during processing. for the girlies who need to know everything. πŸ”
  • -V, --version β€” print the clusterdb version and exit. quick little flex. πŸ’…
  • -?, --help β€” show help about clusterdb command 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 .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. so like, automation bestie. πŸ€–
  • -W, --password β€” 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. so in some cases it is worth typing -W to avoid the extra connection attempt. efficiency slay. ⚑

  • --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, 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 🧚

  • PGDATABASE
  • PGHOST
  • PGPORT
  • PGUSER

β€” default connection parameters. the classic quartet. πŸŽ€

  • PG_COLOR β€” specifies whether to use color in diagnostic messages. possible values are always, auto and never. (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