如何从命令行重新索引Postgres 9.1.3

3

我管理着一个Postgres数据库,其中有一系列的删除和更新操作。由于10分钟后续更新会无限冻结(随机发生),因此建议在删除操作之后安排重新索引作为解决方案。DOS指令提供了以下命令:

Usage:
  reindexdb [OPTION]... [DBNAME]

Options:
  -a, --all                 reindex all databases
  -d, --dbname=DBNAME       database to reindex
  -e, --echo                show the commands being sent to the server
  -i, --index=INDEX         recreate specific index only
  -q, --quiet               don't write any messages
  -s, --system              reindex system catalogs
  -t, --table=TABLE         reindex specific table only
  --help                    show this help, then exit
  --version                 output version information, then exit

Connection options:
  -h, --host=HOSTNAME       database server host or socket directory
  -p, --port=PORT           database server port
  -U, --username=USERNAME   user name to connect as
  -w, --no-password         never prompt for password
  -W, --password            force password prompt

由于这是公司的标准版本,我们必须使用9.1.3版。我已经尝试了我能想到的所有选项,但它无法执行重新索引命令:

reindexdb.exe -U username=MyUserName -W MyPassword -t table=MyDatabase.MyTable

我也尝试过

reindexdb.exe -U MyUserName -W MyPassword -t MyDatabase.MyTable

并且。
reindexdb.exe -U MyUserName -W MyPassword -t MyTable -d MyDatabase

...但它们都以错误结束:

reindexdb: too many command-line arguments (first is "-t")

有没有能够说明正确语法的工作示例?


1
使用密码文件,在Windows上的路径是:%APPDATA%\postgresql\pgpass.conf。详细信息请参考:https://dev59.com/eGUp5IYBdhLWcg3wTGXe#15593100 - Erwin Brandstetter
3个回答

5

MyPassword从参数中删除,并在Postgres提示时输入它。

-W只会导致Postgres提示输入密码;它本身不接受密码。您永远不应在命令行上指定密码,因为通常会被记录。

如果您需要以非交互方式运行它,请设置PGPASSWORD环境变量或创建一个pgpass文件


如果这是一个定时任务批处理文件,我该如何在非交互环境中输入密码? - Phoenix14830

1

任何一个命令都可以通过在关键字后面添加FORCE来强制执行。

重新创建一个单独的索引,名为myindex:

REINDEX INDEX myindex

重新创建表mytable中的所有索引。
REINDEX TABLE mytable

重新创建公共模式中的所有索引:
REINDEX SCHEMA public

重新创建数据库中的所有索引:
REINDEX DATABASE postgres

重新创建数据库postgres中系统目录上的所有索引:
REINDEX SYSTEM postgres

link


1
这就做到了:
reindexdb.exe -d MyDatabase -U postgres -t MyTable

正如@Colonel Thirty Two和@Erwin Brandstetter所指出的那样,可以通过%APPDATA%\postgresql\pgpass.conf完全删除密码。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接