clusterdb
Reclusters tables that were previously clustered with CLUSTER.
Synopsis
clusterdb [ <connection-option> ... ]
[ --verbose | -v ]
[ --table | -t <table> ]
[ [ --dbname | -d ] <dbname> ]
clusterdb [ <connection-option> ... ]
[ --all | -a ]
[ --verbose | -v ]
clusterdb -? | --help
clusterdb -V | --version
Description
To cluster a table means to physically reorder a table on disk according to an index so that index scan operations can access data on disk in a somewhat sequential order, thereby improving index seek performance for queries that use that index.
The clusterdb utility finds any tables in a database that have previously been clustered with the CLUSTER SQL command, and clusters them again on the same index that was last used.
Tables that have never been clustered are not affected.
clusterdb is a wrapper around the SQL command CLUSTER.
Although clustering a table in this way is supported in Greengage DB, it is not recommended because the CLUSTER operation itself is extremely slow.
If you do need to order a table in this way to improve your query performance, use the CREATE TABLE AS statement to reorder the table on disk rather than using CLUSTER.
If you cluster a table in this way, then clusterdb is not relevant.
Options
- -a | --all
-
Cluster all databases.
- [-d] <dbname> | [--dbname=]<dbname>
-
The name of the database to be clustered. 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. - -e | --echo
-
Echo the commands that
clusterdbgenerates and sends to the server. - -q | --quiet
-
Do not display a response.
- -t <table> | --table=<table>
-
Cluster the named table only. Multiple tables can be clustered by writing multiple
-tswitches. - -v | --verbose
-
Print detailed information during processing.
- -V | --version
-
Print the
clusterdbversion and exit. - -? | --help
-
Show help about
clusterdbcommand line arguments, and exit.
Connection options
- -h <host> | --host=<host>
-
The host name of the machine on which the Greengage DB master is running. If not specified, reads from the
PGHOSTenvironment variable or defaults tolocalhost. - -p <port> | --port=<port>
-
The TCP port on which the Greengage DB master is listening for connections. If not specified, reads from the
PGPORTenvironment variable or defaults to5432. - -U <username> | --username=<username>
-
The database role name to connect as. If not specified, reads from the
PGUSERenvironment variable or defaults to the current system role name. - -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.
- -W | --password
-
Force a password prompt.
- --maintenance-db=<dbname>
-
The name of the database to connect to discover what other databases should be clustered. If not specified, the
postgresdatabase will be used, and if that does not exist,template1will be used.
Examples
Cluster the test database:
$ clusterdb test
Cluster the foo table in the xyzzy database:
$ clusterdb --table foo xyzzy