postgreSQL错误initdb:找不到命令

时间:2017-05-22 03:31:23

标签: database postgresql ubuntu

我使用linuxbrew在ubuntu上安装postgresql:

brew install postgresql

它似乎工作正常,但之后因为我第一次安装PostgreSQL我尝试创建数据库:

initdb /usr/local/var/postgres -E utf8

但它返回为:

initdb: command not found

我尝试使用sudo but that doesn't helped

运行命令

3 个答案:

答案 0 :(得分:7)

运行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

所以在我的情况下我想要运行

/usr/local/Cellar/postgresql/9.6.1/bin/initdb 

如果您没有安装mlocate,请安装或使用

sudo find / -name initdb

答案 1 :(得分:5)

我遇到了同样的问题并找到了答案here

Ubuntu路径是

  

/usr/lib/postgresql/9.6/bin/initdb

编辑:对不起,艾哈迈德问起linuxbrew,我正在谈论Ubuntu。       我希望这个答案有助于某人。

答案 2 :(得分:4)

a similar question on SuperUser有一个很好的答案。

简而言之:

  1. Postgres将数据库分组到" clusters",每个数据库都是共享配置和数据位置的命名数据库集合,并在具有自己TCP端口的单个服务器实例上运行。
  2. 如果您只需要一个Postgres实例,则安装包含一个名为" main"的群集,因此您无需运行initdb即可创建一个。
  3. 如果你确实需要多个集群,那么Debian和Ubuntu的Postgres软件包提供了一个不同的命令pg_createcluster来代替initdb,后者不包含在PATH中所以以防止最终用户直接使用它。
  4. 如果您只是尝试创建数据库而不是数据库群集,请改用createdb命令。