database postgreSQL 错误 initdb:找不到命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44104241/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
postgreSQL error initdb: command not found
提问by Ahmed Reza Siddique
i was installing postgresql on ubuntu using linuxbrew:
我正在使用 linuxbrew 在 ubuntu 上安装 postgresql:
brew install postgresql
it seems to work fine but after that because i was installing PostgreSQL for the first time i tried creating a database:
它似乎工作正常,但在那之后因为我是第一次安装 PostgreSQL 我尝试创建一个数据库:
initdb /usr/local/var/postgres -E utf8
but it returned as:
但它返回为:
initdb: command not found
i tried running the command with sudo but that doesn't helped
我试着用 sudo but that doesn't helped
采纳答案by Vao Tsun
run locate initdbit should give you the list to chose. smth like:
运行locate initdb它应该给你选择的列表。喜欢:
MacBook-Air:~ vao$ locate initdb
/usr/local/Cellar/postgresql/9.5.3/bin/initdb
/usr/local/Cellar/postgresql/9.5.3/share/doc/postgresql/html/app-initdb.html
/usr/local/Cellar/postgresql/9.5.3/share/man/man1/initdb.1
/usr/local/Cellar/postgresql/9.6.1/bin/initdb
/usr/local/Cellar/postgresql/9.6.1/share/doc/postgresql/html/app-initdb.html
/usr/local/Cellar/postgresql/9.6.1/share/man/man1/initdb.1
/usr/local/bin/initdb
/usr/local/share/man/man1/initdb.1
So in my case I want to run
所以就我而言,我想跑
/usr/local/Cellar/postgresql/9.6.1/bin/initdb
If you don't have mlocate installed, either install it or use
如果您没有安装 mlocate,请安装它或使用
sudo find / -name initdb
回答by user3787194
I had the same problem and found the answer here.
我遇到了同样的问题,并在这里找到了答案。
Ubuntu path is
Ubuntu路径是
/usr/lib/postgresql/9.6/bin/initdb
/usr/lib/postgresql/9.6/bin/initdb
Edit: Sorry, Ahmed asked about linuxbrew, I'm talking about Ubuntu. I Hope this answer helps somebody.
编辑:抱歉,Ahmed 问了 linuxbrew,我说的是 Ubuntu。我希望这个答案对某人有所帮助。
回答by David Scarlett
There's a good answer to a similar question on SuperUser.
SuperUser 上的类似问题有一个很好的答案。
In short:
简而言之:
- Postgres groups databases into "clusters", each of which is a named collection of databases sharing a configuration and data location, and running on a single server instance with its own TCP port.
- If you only want a single instance of Postgres, the installation includes a cluster named "main", so you don't need to run
initdbto create one. - If you do need multiple clusters, then the Postgres packages for Debian and Ubuntu provide a different command
pg_createclusterto be used instead ofinitdb, with the latter not included inPATHso as to discourage end users from using it directly.
- Postgres 将数据库分组为“集群”,每个集群都是共享配置和数据位置的命名数据库集合,并在具有自己的 TCP 端口的单个服务器实例上运行。
- 如果您只需要 Postgres 的单个实例,则安装包含一个名为“main”的集群,因此您无需运行
initdb即可创建。 - 如果您确实需要多个集群,那么 Debian 和 Ubuntu 的 Postgres 包提供了一个不同的命令
pg_createcluster来代替initdb,后者不包括在内,PATH以阻止最终用户直接使用它。
And if you're just trying to create a database, not a database cluster, use the createdbcommand instead.
如果您只是尝试创建数据库,而不是数据库集群,请改用该createdb命令。

