↑↓ 选择 ↵ 打开 ⌫ 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / 命令行工具 / 客户端程序

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生成并发送给服务器的命令。

-i index
--index=index

只重建index。可以通过写多个-i开关来重建多个索引。

-j njobs
--jobs=njobs

通过同时运行njobs个命令来并行执行重建索引命令。此选项可能缩短处理时间,但也会增加数据库服务器上的负载。

reindexdb将打开njobs个到数据库的连接,因此请确保max_connections设置足够高,能容纳所有连接。

注意,该选项与--system选项不兼容。

-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命令行参数的帮助信息,并退出。

reindexdb也接受下列命令行参数作为连接参数:

-h host
--host=host

指定服务器所在机器的主机名。如果该值以斜杠开头,则它将被用作 Unix 域套接字的目录。

-p port
--port=port

指定服务器监听连接所用的 TCP 端口或本地 Unix 域套接字文件扩展名。

-U username
--username=username

连接时所使用的用户名。

-w
--no-password

永远不发出密码提示。如果服务器要求密码认证,而又无法通过其他方式获取密码,例如通过.pgpass文件,则连接尝试会失败。此选项可用于没有用户可输入密码的批处理作业和脚本。

-W
--password

强制reindexdb在连接数据库前提示输入密码。

该选项并非必需,因为如果服务器要求密码认证,reindexdb会自动提示输入密码。不过,reindexdb会先浪费一次连接尝试来确认服务器需要密码。在某些场景下,值得使用 -W,以避免这次额外的连接尝试。

--maintenance-db=dbname

当使用-a/--all时,连接到该数据库以收集要重建索引的数据库列表。如果未指定,则使用postgres数据库;如果它不存在,则使用template1。这可以是一个连接字符串。如果是这样,连接字符串参数将覆盖任何冲突的命令行选项。此外,除数据库名称本身以外的连接字符串参数,在连接到其他数据库时也会被重复使用。

环境

PGDATABASE
PGHOST
PGPORT
PGUSER

默认连接参数

PG_COLOR

指定诊断消息是否使用颜色。可选值为 always、auto和 never。

与大多数其他 PostgreSQL 工具一样,此工具也使用 libpq 支持的环境变量(见第 32.15 节)。

诊断

如果遇到问题,请参见REINDEX和psql中关于潜在问题和错误消息的讨论。数据库服务器必须在目标主机上运行。此外,libpq前端库所使用的任何默认连接设置和环境变量都会生效。

示例

要重建数据库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 16 → 17: 属性变化。

以下差异保留原始字段名与英文源描述。

--- PostgreSQL 16
+++ PostgreSQL 17
@@ -42,7 +42,7 @@
       "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.",
+      "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 --system option.",
       "names": [
         "-j njobs",
         "--jobs= njobs"
@@ -161,8 +161,6 @@
     }
   ],
   "synopsis": [
-    "reindexdb [ connection-option ...] [ option ...] [ -S | --schema schema ] ... [ -t | --table table ] ... [ -i | --index index ] ... [ dbname ]",
-    "reindexdb [ connection-option ...] [ option ...] -a | --all",
-    "reindexdb [ connection-option ...] [ option ...] -s | --system [ dbname ]"
+    "reindexdb [ connection-option ...] [ option ...] [ -S | --schema schema ] ... [ -t | --table table ] ... [ -i | --index index ] ... [ -s | --system ] [ dbname | -a | --all ]"
   ]
 }

比较已记录的接口与属性,排除来源指纹和构建元数据。某个样本中没有记录,不能据此判断实际引入或移除的版本。

相关条目

导出 JSON · 返回命令行工具 · 收录范围为 PostgreSQL 10 至 20;最早采样版本不一定是实际引入版本。