-bash: initdb: command not found

Dhruv Ghulati picture Dhruv Ghulati · Nov 19, 2014 · Viewed 6.9k times · Source

I have installed PostgreSQL using the EnterpriseDB installation.

I ran sudo ./postgresql-9.3.5-3-osx.app/Contents/MacOS/installbuilder.sh --mode unattended and then ran open /Applications/TextEdit.app .profile to edit my .profile file newly created in /Users/Dhruv to add the line source /Library/PostgreSQL/9.3/pg_env.sh.

Running createuser Dhruv --pwprompt --username=postgres I got

-bash: createuser: command not found

Then running unknown-88-1f-a1-1b-c2-ec:9.3 dhruv$ sudo -u postgres /bin/createuser and various other methods I was able to set up something using some sort of password prompt. I know this later because using sudo -u postgres /Library/PostgreSQL/9.3/bin/createuser I got

createuser: creation of new role failed: ERROR: role "postgres" already exists

Running then initdb -D /Library/PostgreSQL/9.3/data I get

-bash: initdb: command not found.

Similiarly, if I try the same thing but while connected to postgres, sudo su - postgres and then initdb -D /Library/PostgreSQL/9.3/data I get again

-bash: initdb: command not found.

At a loss at what to do. 1) how do I know details of this supposed role "postgres" I created magically and 2) why is initdb not working?

Answer

carrotandapple picture carrotandapple · Apr 28, 2017

How I fixed this is run brew doctor, and you might see the postgresql un der the Warning: that indicates there's unlinked kegs in your Cellar. Try to run brew link postgresql. It will show some symlinks got created. Then run init db ... again.

Hope this help!