reindexdb
reindexdb — 重建一个 PostgreSQL 数据库中的索引
当前查看 PostgreSQL 18.6。
说明
reindexdb — 重建一个 PostgreSQL 数据库中的索引
- 手册中的可执行程序
- reindexdb
- 程序版本
- 18.6
- 参考清单
- 客户端程序
- 选项定义组
- 19
用法
reindexdb [ connection-option ...] [ option ...] [ -S | --schema schema ] ... [ -t | --table table ] ... [ -i | --index index ] ... [ -s | --system ] [ dbname | -a | --all ]手册中的选项
| 选项与参数 | 说明 |
|---|---|
| -a --all | 重建所有数据库的索引。 |
| --concurrently | 使用 CONCURRENTLY 选项。参见 REINDEX ,其中详细解释了该选项的所有注意事项。 |
| -e --echo | 回显 reindexdb 生成并发送给服务器的命令。 |
| -i index --index= index | 只重建 index 。可以通过写多个 -i 开关来重建多个索引。 |
| -j njobs --jobs= njobs | 通过同时运行 njobs 个命令来并行执行重建索引命令。此选项可能缩短处理时间,但也会增加数据库服务器上的负载。 |
| -q --quiet | 不显示进度消息。 |
| -s --system | 仅重建数据库的系统目录上的索引。 |
| -S schema --schema= schema | 只重建 schema 中的索引。可以通过写多个 -S 开关来重建多个模式中的索引。 |
| -t table --table= table | 只重建 table 上的索引。可以通过写多个 -t 开关来重建多个表上的索引。 |
| --tablespace= tablespace | 指定重建索引所在的表空间。(该名称会按双引号标识符处理。) |
| -v --verbose | 在处理过程中打印详细信息。 |
| -V --version | 打印 reindexdb 的版本并退出。 |
| -? --help | 显示关于 reindexdb 命令行参数的帮助信息,并退出。 |
| -h host --host= host | 指定服务器所在机器的主机名。如果该值以斜杠开头,则它将被用作 Unix 域套接字的目录。 |
| -p port --port= port | 指定服务器监听连接所用的 TCP 端口或本地 Unix 域套接字文件扩展名。 |
| -U username --username= username | 连接时所使用的用户名。 |
| -w --no-password | 永远不发出密码提示。如果服务器要求密码认证,而又无法通过其他方式获取密码,例如通过 .pgpass 文件,则连接尝试会失败。此选项可用于没有用户可输入密码的批处理作业和脚本。 |
| -W --password | 强制 reindexdb 在连接数据库前提示输入密码。 |
| --maintenance-db= dbname | 当使用 -a / --all 时,连接到该数据库以收集要重建索引的数据库列表。如果未指定,则使用 postgres 数据库;如果它不存在,则使用 template1 。这可以是一个 连接字符串 。如果是这样,连接字符串参数将覆盖任何冲突的命令行选项。此外,除数据库名称本身以外的连接字符串参数,在连接到其他数据库时也会被重复使用。 |
环境变量
| 变量 | 含义 |
|---|---|
| PGDATABASE PGHOST PGPORT PGUSER | 默认连接参数 |
| PG_COLOR | 指定诊断消息是否使用颜色。可选值为 always 、 auto 和 never 。 |
手册定义
reindexdb
reindexdb — 重建一个PostgreSQL数据库中的索引
大纲
reindexdb [connection-option...] [option...] [ -S | --schema schema ] ... [ -t | --table table ] ... [ -i | --index index ] ... [ -s | --system ] [ dbname | -a | --all ]
说明
reindexdb是用于重建PostgreSQL数据库中索引的工具。
reindexdb是SQL命令REINDEX的一个包装器。通过该工具重建索引与通过其他方法访问服务器来重建索引,在效果上没有区别。
选项
reindexdb接受下列命令行参数:
-a--all-
重建所有数据库的索引。
--concurrently-
使用
CONCURRENTLY选项。参见REINDEX,其中详细解释了该选项的所有注意事项。 [-d]dbname[--dbname=]dbname-
在未使用
-a/--all时,指定要重建索引的数据库名称。如果未指定该选项,则从环境变量PGDATABASE中读取数据库名称。如果该变量未设置,则使用为连接指定的用户名。dbname可以是一个连接字符串。如果是这样,连接字符串参数将覆盖任何冲突的命令行选项。 -e--echo-
回显reindexdb生成并发送给服务器的命令。
-iindex--index=index-
只重建
index。可以通过写多个-i开关来重建多个索引。 -jnjobs--jobs=njobs-
通过同时运行
njobs个命令来并行执行重建索引命令。此选项可能缩短处理时间,但也会增加数据库服务器上的负载。reindexdb将打开
njobs个到数据库的连接,因此请确保max_connections设置足够高,能容纳所有连接。注意,该选项与
--system选项不兼容。 -q--quiet-
不显示进度消息。
-s--system-
仅重建数据库的系统目录上的索引。
-Sschema--schema=schema-
只重建
schema中的索引。可以通过写多个-S开关来重建多个模式中的索引。 -ttable--table=table-
只重建
table上的索引。可以通过写多个-t开关来重建多个表上的索引。 --tablespace=tablespace-
指定重建索引所在的表空间。(该名称会按双引号标识符处理。)
-v--verbose-
在处理过程中打印详细信息。
-V--version-
打印reindexdb的版本并退出。
-?--help-
显示关于reindexdb命令行参数的帮助信息,并退出。
reindexdb也接受下列命令行参数作为连接参数:
-hhost--host=host-
指定服务器所在机器的主机名。如果该值以斜杠开头,则它将被用作 Unix 域套接字的目录。
-pport--port=port-
指定服务器监听连接所用的 TCP 端口或本地 Unix 域套接字文件扩展名。
-Uusername--username=username-
连接时所使用的用户名。
-w--no-password-
永远不发出密码提示。如果服务器要求密码认证,而又无法通过其他方式获取密码,例如通过
.pgpass文件,则连接尝试会失败。此选项可用于没有用户可输入密码的批处理作业和脚本。 -W--password-
强制reindexdb在连接数据库前提示输入密码。
该选项并非必需,因为如果服务器要求密码认证,reindexdb会自动提示输入密码。不过,reindexdb会先浪费一次连接尝试来确认服务器需要密码。在某些场景下,值得使用
-W,以避免这次额外的连接尝试。 --maintenance-db=dbname-
当使用
-a/--all时,连接到该数据库以收集要重建索引的数据库列表。如果未指定,则使用postgres数据库;如果它不存在,则使用template1。这可以是一个连接字符串。如果是这样,连接字符串参数将覆盖任何冲突的命令行选项。此外,除数据库名称本身以外的连接字符串参数,在连接到其他数据库时也会被重复使用。
环境
PGDATABASEPGHOSTPGPORTPGUSER-
默认连接参数
PG_COLOR-
指定诊断消息是否使用颜色。可选值为
always、auto和never。
与大多数其他 PostgreSQL 工具一样,此工具也使用 libpq 支持的环境变量(见第 32.15 节)。
示例
要重建数据库test中的索引:
$reindexdb test
重建名为 abcd 的数据库中的表 foo 和索引 bar 的索引:
$reindexdb --table=foo --index=bar abcd
另见
REINDEX文档与源码
来源构建
- 版本
- 18.6
- 构建
- https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2
- 来源指纹
ee8d1a3612338fd9adf250730cb640fcc5233b5491337cc00a316a44e3a0b9f8
版本比较
PostgreSQL 12 → 13: 属性变化。
以下差异保留原始字段名与英文源描述。
--- PostgreSQL 12
+++ PostgreSQL 13
@@ -40,6 +40,14 @@
"--index= index"
],
"signature": "-i index --index= index"
+ },
+ {
+ "description": "Execute the reindex commands in parallel by running njobs commands simultaneously. This option may reduce the processing time but it also increases the load on the database server. reindexdb will open njobs connections to the database, so make sure your max_connections setting is high enough to accommodate all connections. Note that this option is incompatible with the --index and --system options.",
+ "names": [
+ "-j njobs",
+ "--jobs= njobs"
+ ],
+ "signature": "-j njobs --jobs= njobs"
},
{
"description": "Do not display progress messages.",
@@ -138,7 +146,7 @@
"signature": "-W --password"
},
{
- "description": "Specifies the name of the database to connect to to discover which databases should be reindexed, when -a / --all is used. 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 . 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.",
+ "description": "When the -a / --all is used, connect to this database to gather the list of databases to reindex. 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 . 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.",
"names": [
"--maintenance-db= dbname"
],
比较已记录的接口与属性,排除来源指纹和构建元数据。某个样本中没有记录,不能据此判断实际引入或移除的版本。
相关条目
导出 JSON · 返回命令行工具 · 收录范围为 PostgreSQL 10 至 20;最早采样版本不一定是实际引入版本。