3

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?

arcyqwerty
  • 10,325
  • 4
  • 47
  • 84
Dhruv Ghulati
  • 2,976
  • 3
  • 35
  • 51

3 Answers3

5

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!

carrotandapple
  • 101
  • 1
  • 8
0

Who are you logged in as?

When you do sudo or su -, it will run init scripts for root, such as .bashrc and .bash_profile.

These may set up difference executable search paths between root, postgres, and you.

Try something like sudo initdb, or su - postgres -c initdb ... whichever user has the paths constructed correctly, so that the path gets set up.

You could also duplicate the path/lib creation code in your own environment, but that will break if it is ever changed.

David Elson
  • 211
  • 2
  • 3
  • How do I find out who I am logged in as? In my own shell I have unknown-88-1f-a1-1b-c2-ec:bin dhruv$. I tried both what you said, for 'sudo initdb' I first got asked for a password then I got 'sudo: initdb: command not found'. For 'su - postgres -c initdb -D /Library/PostgreSQL/9.3/data' I got 'Password:' as a prompt, then whatever I type in I get 'su: Sorry'. – Dhruv Ghulati Nov 19 '14 at 12:21
0

Same thing happened to me. I'm new to OS X coming from Linux, here's what I had to do. I installed postgres via homebrew and when I did so I noticed it put everything it download to: /usr/local/Cellar/postgresql/($postgres_version)/

When I cd'd into that folder I saw a directory named bin so I cd'd and saw initdb right there. So I had to then add this to my path so I could use the command:

$ export PATH=/usr/local/Cellar/postgresql/9.4.4/bin:$PATH

hope that helps you

  • I don't know about PostgreSQL, but normally with `homebrew` you only ever add `/usr/local/bin` to your PATH as it symlinks from there to the Cellar. I would respectfully suggest you check that and consider running `brew doctor` too to health check yourself. Later on, when you do `brew upgrade xyz` the symlink in `/usr/local/bin` will change automatically to the new version for you whereas your PATH with a version number in it will not... – Mark Setchell Jul 17 '15 at 08:01