Estefy
Estefy

Reputation: 434

Permission denied when connecting to server Postgres

I install Postgres9.5.1 via Homebrew. However, I am having problems creating a database by using "createdb". Originally the message said: "createdb: command not found". Then I uninstall and install Homebrew and updated Postgres.

However, now I am getting a new error:

 createdb: could not connect to database template1: could not connect to      server: No such file or directory
     Is the server running locally and accepting
     connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

I tried a couple of things such as:

 $rm /usr/local/var/postgres/postmaster.pid

which gave back:

"Permission denied"

Also:

 $postgres -D /usr/local/var/postgres
 postgres cannot access the server configuration file                "/usr/local/var/postgres/postgresql.conf": Permission denied

Or:

 $grep unix_socket /usr/local/var/postgres/postgresql.conf
 grep: /usr/local/var/postgres/postgresql.conf: Permission denied

I don't know what to do, I don't really understand what is going on. Thanks.

Upvotes: 2

Views: 5325

Answers (1)

Estefy
Estefy

Reputation: 434

After dealing with this problem for days I finally managed to solve it by uninstalling and installing Postgresql via Homebrew and initiating the server. This is how I did it:

make sure Xcode (for Os X users) is up to date

  xcode-select --install

Install Homebrew

  ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  brew doctor
  brew search
  brew install postgres
  brew update

Postgres should be install. Now, make sure you have the permissions required to use it, this is done by allowing your user such permission:

  sudo chown -R :admin /usr/local

The permission problem should be solved. Now you (as I did) could be facing a problem related to the server.

     psql -U postgres -p 5432 -h localhost

This will do the trick:

     launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
     mv /usr/local/var/postgres /usr/local/var/postgres-deletemewhenitsallgood
     initdb /usr/local/var/postgres -E utf8
     launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

or

     rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8

You can now start the database server using:

pg_ctl -D /usr/local/var/postgres -l logfile start

Don't forget to adapt this command lines to your specific case and addresses.

Good luck

Upvotes: 9

Related Questions