0

This is the third time I'm setting up Postgres on a new machine (OS X 10.9 this time), and the third time I'm having problems with the connection.

Basically, I'm at the point where I've created a database cluster and can start postgres using:

postgres -D /usr/local/pgsql/data

But I want it to run in the background as a launch daemon, so I

sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql91-server.plist

It seems like the daemon is launched successfully. But when I type psql I get the same old error message I've been dealing with every single time I try to set up Postgres:

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

Any ideas on what might be causing this?

1 Answers1

1

The psql you're running is the old version bundled by Apple in Mac OS X and added to the default PATH. Use the one from Homebrew, by fixing your path or entering the path specifically.

Alternately, explicitly connect to the server by overriding the default socket directory:

psql -h /tmp

See also:

Update:

In this case it looks like the server is genuinely not starting. Check the permissions on the data directory (apparently /usr/local/pgsql/data) and check the Console.app logs for relevant messages from launchd.

Update:

You must fix the permissions so the postgres user (or postgres_, depending on how you installed) has ownership. Check the launchd config file to see what user it runs as, and sudo chown -R postgres /usr/local/pgsql/data to change ownership. Replace postgres with postgres_ if that's what your launchd config says

Community
  • 1
  • 1
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
  • I'll try this shortly. I used Macports, rather than Homebrew, but I guess it's the same thing in this regard. –  Mar 06 '14 at 08:27
  • So, it seems like the path is set up correctly. `psql -h /tmp` does not work. My path begins with `/opt/local/lib/postgresql91/bin`. Not really sure where to continue debugging from here. –  Mar 06 '14 at 12:55
  • Also, when I grep the launchctl services, `orc.macports.postgresql91-server` displays `-` as its status. It does not change when I start, stop, load or unload the process. –  Mar 06 '14 at 13:19
  • Check the PostgreSQL server error log files, then. Anything there? Or in the Consle logs? (Wondering about data-directory permissions issues in particular). – Craig Ringer Mar 06 '14 at 13:49
  • The `/opt/local/var/log/postgresql91/postgres.log` file is empty. Is there any other log file? –  Mar 06 '14 at 14:00
  • Additionally, `whereis psql` displays an empty result. On my other machine where Postgres is set up properly, the same command displays `/usr/bin/psql`. Is that relevant? –  Mar 06 '14 at 15:08
  • Ok, so I can connect using `postgres -D /usr/local/pgsql/data`, but the launchdaemon doesn't seem to be working. Any clues? –  Mar 06 '14 at 15:25
  • Check the Console.app logs for launchd. I bet the data directory permissions are wrong. – Craig Ringer Mar 06 '14 at 23:11
  • Well, if it's not starting and there's nothing in the PostgreSQL logs there should be in Console.app logs. Anyway, what's `ls -ld /usr/local/pgsql/data` report? – Craig Ringer Mar 07 '14 at 00:03
  • `drxw----- 18 myappleusername wheel 612 date /usr/local/pgsql/data/` –  Mar 07 '14 at 00:41
  • @trevorDashDash Well, there's your problem. You must fix the permissions so the `postgres` user (or `postgres_`, depending on how you installed) has ownership. Check the launchd config file to see what user it runs as, and `sudo chown -R postgres /usr/local/pgsql/data` to change ownership. Replace `postgres` with `postgres_` if that's what your launchd config says. – Craig Ringer Mar 07 '14 at 00:43
  • Ok, that actually did it when I restarted launchd. Thanks a ton! This is way over my head. –  Mar 07 '14 at 00:51