← 返回命令列表

Linux command

clusterdb 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Cluster all tables

clusterdb [database_name]

Cluster a specific table

clusterdb --table [table_name] [database_name]

Cluster all databases

clusterdb --all

Cluster with connection options

clusterdb --host [hostname] --port [5432] --username [user] [database]

Cluster with verbose output

clusterdb --verbose [database_name]

Cluster using a specific index

clusterdb --table [table_name] --index [index_name] [database_name]

Echo commands being executed

clusterdb --echo [database_name]

说明

clusterdb is a PostgreSQL utility for reclustering tables in a database. Clustering physically reorders a table's data rows to match the order of an index, which can significantly improve performance for range queries that use that index. When a table is clustered on an index, data rows are physically sorted in index order on disk. This reduces disk I/O for queries that scan ranges of index values, as sequential disk access is faster than random access. However, the cluster ordering degrades over time as rows are inserted, updated, or deleted. The command is a wrapper around the SQL CLUSTER command, providing a convenient way to cluster tables from the command line. Without the -t option, it clusters all previously-clustered tables in the database. Clustering is a one-time operation that does not maintain physical order over time. Regular reclustering may be needed for tables with frequent updates. The operation requires exclusive access to the table and can be resource-intensive for large tables.

参数

-a, --all
Cluster all databases on the server.
-d, --dbname _dbname_
Database to cluster.
-t, --table _table_
Cluster only the specified table.
-i, --index _index_
Use the specified index for clustering the table.
-v, --verbose
Print detailed information during processing.
-e, --echo
Echo the commands being sent to the server.
-q, --quiet
Do not display progress messages.
-h, --host _hostname_
Database server host (default: local socket or localhost).
-p, --port _port_
Database server port (default: 5432).
-U, --username _username_
Username to connect as.
-w, --no-password
Never prompt for password.
-W, --password
Force password prompt.
--maintenance-db _dbname_
Database to connect to when using `-a`/`--all` (defaults to `postgres` or `template1`).
-V, --version
Print version information.
-?, --help
Show help about command-line arguments.

FAQ

What is the clusterdb command used for?

clusterdb is a PostgreSQL utility for reclustering tables in a database. Clustering physically reorders a table's data rows to match the order of an index, which can significantly improve performance for range queries that use that index. When a table is clustered on an index, data rows are physically sorted in index order on disk. This reduces disk I/O for queries that scan ranges of index values, as sequential disk access is faster than random access. However, the cluster ordering degrades over time as rows are inserted, updated, or deleted. The command is a wrapper around the SQL CLUSTER command, providing a convenient way to cluster tables from the command line. Without the -t option, it clusters all previously-clustered tables in the database. Clustering is a one-time operation that does not maintain physical order over time. Regular reclustering may be needed for tables with frequent updates. The operation requires exclusive access to the table and can be resource-intensive for large tables.

How do I run a basic clusterdb example?

Run `clusterdb [database_name]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -a, --all do in clusterdb?

Cluster all databases on the server.