繁体   English   中英

postgreSQL 错误 initdb: command not found

[英]postgreSQL error initdb: command not found

我正在使用 linuxbrew 在 ubuntu 上安装 postgresql:

brew install postgresql

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

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

但它返回为:

initdb: command not found

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

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

对SuperUser上的类似问题有一个很好的答案。

简而言之:

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

如果您只是尝试创建数据库而不是数据库集群,请使用createdb命令。

我有同样的问题,在这里找到答案。

Ubuntu路径是

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

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

我有一个类似的问题,因为brew install postgresql没有正确链接 postgres。 我的解决方案是运行:

brew link --overwrite postgresql

您可以添加 PATH 以从任何位置运行

sudo nano ~/.profile

里面 nano go 到最后并添加以下内容

# set PATH so it includes user's private bin if it exists
if [ -d "/usr/lib/postgresql/14/bin/" ] ; then
    PATH="/usr/lib/postgresql/14/bin/:$PATH"
fi

并配置替代方案

sudo update-alternatives --install /usr/bin/initdb initdb /usr/lib/postgresql/14/bin/initdb 1

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM