如何从命令行重新索引 Postgres 9.1.3
How to reindex Postgres 9.1.3 from the command line
我对我管理的 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")
有没有人有可以阐明正确语法的工作示例?
从您的参数中删除 MyPassword
,并在 Postgres 提示您时输入它。
-W
只是让 Postgres 提示输入密码;它不接受密码本身。永远不要在命令行上指定密码,因为它通常会被记录下来。
如果您需要以非交互方式运行,请设置 PGPASSWORD
environment variable or create a pgpass
file。
做到了:
reindexdb.exe -d MyDatabase -U postgres -t MyTable
正如@Colonel 三十二和@Erwin Brandstetter 指出的那样,可以通过 %APPDATA%\postgresql\pgpass.conf
完全删除密码
任何这些都可以通过在命令后添加关键字 FORCE 来强制执行
重新创建单个索引,myindex:
REINDEX INDEX myindex
重新创建 table 中的所有索引,mytable:
REINDEX TABLE mytable
重新创建架构中的所有索引 public:
REINDEX SCHEMA public
重新创建数据库 postgres 中的所有索引:
REINDEX DATABASE postgres
在数据库 postgres 中重新创建系统目录的所有索引:
REINDEX SYSTEM postgres
我对我管理的 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")
有没有人有可以阐明正确语法的工作示例?
从您的参数中删除 MyPassword
,并在 Postgres 提示您时输入它。
-W
只是让 Postgres 提示输入密码;它不接受密码本身。永远不要在命令行上指定密码,因为它通常会被记录下来。
如果您需要以非交互方式运行,请设置 PGPASSWORD
environment variable or create a pgpass
file。
做到了:
reindexdb.exe -d MyDatabase -U postgres -t MyTable
正如@Colonel 三十二和@Erwin Brandstetter 指出的那样,可以通过 %APPDATA%\postgresql\pgpass.conf
完全删除密码任何这些都可以通过在命令后添加关键字 FORCE 来强制执行
重新创建单个索引,myindex:
REINDEX INDEX myindex
重新创建 table 中的所有索引,mytable:
REINDEX TABLE mytable
重新创建架构中的所有索引 public:
REINDEX SCHEMA public
重新创建数据库 postgres 中的所有索引:
REINDEX DATABASE postgres
在数据库 postgres 中重新创建系统目录的所有索引:
REINDEX SYSTEM postgres