ubuntu PostgreSQL错误initdb:未找到命令

vi4fp9gy  于 5个月前  发布在  PostgreSQL
关注(0)|答案(6)|浏览(114)

我在Ubuntu上使用LinuxBrew安装了PostgreSQL:

brew install postgresql

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

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


但它返回为:

initdb: command not found


我试着用sudo but that doesn't helped运行命令

hfwmuf9z

hfwmuf9z1#

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

pexxcrt2

pexxcrt22#

a similar question on SuperUser有一个好答案。
简而言之:

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

pftdvrlh3#

我遇到了同样的问题,找到了答案here
Ubuntu路径
/usr/lib/postgresql/9.6/bin/initdb
编辑:对不起,艾哈迈德问了关于linuxbrew的问题,我说的是Ubuntu。我希望这个答案能帮助到一些人。

yftpprvb

yftpprvb4#

我有一个类似的问题,由brew install postgresql没有正确链接postgres引起的。对我来说,解决办法是运行:

brew link --overwrite postgresql

字符串

nhn9ugyo

nhn9ugyo5#

如果你安装了postgresql并得到了initdb: command not found
你应该在~/.bashrc(OR .zshrc)文件中添加下面一行:
export PATH=$PATH:/usr/lib/postgresql/x.y/bin/
然后
source ~/.bashrc
实际上,initdb是存在于该路径。之后,您可以使用initdb命令。

hgc7kmma

hgc7kmma6#

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

sudo nano ~/.profile

字符串
在nano内部,转到最后并添加以下内容

# 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

相关问题