I am trying to setup pg on a relatively clean lion install and it's not being successful.

First I successfully installed homebrew, and installed postgresql without any errors.

Then I tried to run a rails app, got an error. Tried running this script: http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/

in order to hide the default system postgres install, but now I am getting the following error:

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"?

When I try to run the postgres script in the bin directory I get the following error:

larson:~ larson$ /usr/local/Cellar/postgresql/9.1.3/bin/postgres ; exit;
postgres does not know where to find the server configuration file.
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.

It's clear that postgres cannot start because it is not configured correctly. Does anybody have any advice on the proper way to configure it so it starts?

  • 1
    Well it can't find the configuration file, have you checked if there are any configuration files? – Lucas Kauffman Apr 27 '12 at 18:34
  • I did a spotlight search for pg_hba.conf and cannot find it – Andrew Lauer Barinov Apr 27 '12 at 18:49
  • Well there's your answer :) – Lucas Kauffman Apr 27 '12 at 18:50
  • Ok got it, so on Snow Leopard there was a directory called postgresql in larson/Library/Developer (larson is my user name), it contained logs, config files, etc. On a lion install that directory isn't there. Do you know the right place to look for it or a method to instruct postgres to put the directory in the right place? – Andrew Lauer Barinov Apr 27 '12 at 18:53
  • try /usr/local/pgsql – Lucas Kauffman Apr 27 '12 at 18:57

Blindly running homebrew scripts with no idea what they're doing doesn't solve problems - it CREATES them. End Rant.

We don't know what the error you had before was, but now you apparently don't have a database cluster configured.

You need to properly set up your Postgres cluster (see the Postgres manual), and/or tell postgres where the database cluster lives when you start it (that's that bit about You must specify the --config-file or -D invocation option or set the PGDATA environment variable. from the error message). Section 17.3 of the manual talks about this.


Running brew info postgres gives you basics to get things going. For example:

If this is your first install, create a database with:

initdb /usr/local/var/postgres -E utf8

Or to restart the database server:

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
  • what user should this be run under? – SuperUberDuper Jul 16 '16 at 8:57

Per discussion on this Homebrew issue: https://github.com/Homebrew/homebrew/issues/21920

you may just need to do this:

export PGDATA=/usr/local/var/postgres

Just check and see that the directory does indeed live there and has the postgres configuration files.

  • 1
    Did it for me. This is the answer. – geoyws Aug 14 '15 at 14:44

Did you run initdb? I found this issue with a default install of postgres 9.1.3. It looks like initdb builds the database directory with config.

This is included in the instructions that came with the brew install.
Try brew info postgresql and read about 'new install'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.