Database postgreSQL错误initdb:未找到命令

Database postgreSQL错误initdb:未找到命令,database,postgresql,ubuntu,Database,Postgresql,Ubuntu,我使用linuxbrew在ubuntu上安装postgresql: brew install postgresql 它似乎工作正常,但在那之后,因为我第一次尝试创建数据库时安装了PostgreSQL: initdb /usr/local/var/postgres -E utf8 但结果是: initdb: command not found 我尝试使用sudo运行该命令,但这无助于运行查找initdb,它应该会提供要选择的列表。smth类似: MacBook-Air:~ vao$ loca

我使用linuxbrew在ubuntu上安装postgresql:

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

initdb /usr/local/var/postgres -E utf8
但结果是:

initdb: command not found

我尝试使用
sudo运行该命令,但这无助于

运行
查找initdb
,它应该会提供要选择的列表。smth类似:

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
有一个很好的答案

简言之:

  • Postgres将数据库分组为“集群”,每个集群都是共享一个配置和数据位置的数据库的命名集合,在一个具有自己TCP端口的服务器实例上运行
  • 如果您只需要一个Postgres实例,那么安装包含一个名为“main”的集群,因此您不需要运行
    initdb
    来创建一个实例
  • 如果您确实需要多个集群,那么Debian和Ubuntu的Postgres包提供了一个不同的命令来代替
    initdb
    ,后者不包括在
    PATH
    中,以阻止最终用户直接使用它

  • 如果您只是试图创建一个数据库,而不是一个数据库集群,那么请使用该命令。

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

    Ubuntu路径是

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

    编辑:对不起,艾哈迈德问起linuxbrew,我说的是Ubuntu。 我希望这个答案对某人有所帮助