postgreSQL error initdb: command not found
Solution 1
run locate initdb
it should give you the list to chose. 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
sudo find / -name initdb
Solution 2
There's a good answer to a similar question on SuperUser.
In short:
- 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.
- 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. - If you do need multiple clusters, then the Postgres packages for Debian and Ubuntu provide a different command
pg_createcluster
to be used instead ofinitdb
, with the latter not included inPATH
so as to discourage end users from using it directly.
And if you're just trying to create a database, not a database cluster, use the createdb
command instead.
Solution 3
I had the same problem and found the answer here.
Ubuntu path is
/usr/lib/postgresql/9.6/bin/initdb
Edit: Sorry, Ahmed asked about linuxbrew, I'm talking about Ubuntu. I Hope this answer helps somebody.
Ahmed Reza Siddique
Updated on July 10, 2022Comments
-
Ahmed Reza Siddique almost 2 years
i was installing postgresql on ubuntu using linuxbrew:
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:
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