简体   繁体   English

postgreSQL 错误 initdb: command not found

[英]postgreSQL error initdb: command not found

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

run locate initdb it should give you the list to chose. 运行locate initdb它应该给你选择的列表。 smth like: 像:

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

There's a good answer to a similar question on SuperUser . 对SuperUser上的类似问题有一个很好的答案。

In short: 简而言之:

  1. 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. Postgres将数据库分组为“集群”,每个集群都是共享配置和数据位置的命名数据库集合,并在具有自己TCP端口的单个服务器实例上运行。
  2. If you only want a single instance of Postgres, the installation includes a cluster named "main", so you don't need to run initdb to create one. 如果您只需要一个Postgres实例,则安装包含一个名为“main”的集群,因此您无需运行initdb来创建一个。
  3. If you do need multiple clusters, then the Postgres packages for Debian and Ubuntu provide a different command pg_createcluster to be used instead of initdb , with the latter not included in PATH so as to discourage end users from using it directly. 如果你确实需要多个集群,那么Debian和Ubuntu的Postgres包提供了一个不同的命令pg_createcluster来代替initdb ,后者不包含在PATH ,以阻止最终用户直接使用它。

And if you're just trying to create a database, not a database cluster, use the createdb command instead. 如果您只是尝试创建数据库而不是数据库集群,请使用createdb命令。

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. 编辑:对不起,艾哈迈德问linuxbrew,我说的是Ubuntu。 I Hope this answer helps somebody. 我希望这个答案有助于某人。

I had a similar issue caused by the brew install postgresql not properly linking postgres.我有一个类似的问题,因为brew install postgresql没有正确链接 postgres。 The solve for me was to run:我的解决方案是运行:

brew link --overwrite postgresql

you can add the PATH to run from any location您可以添加 PATH 以从任何位置运行

sudo nano ~/.profile

inside nano go to the end and add the following里面 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

and configure the alternative并配置替代方案

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