5

After upgrading to Lion, I get the following error when trying to start up the Postgres server:

pg_ctl: could not open PID file "/usr/local/var/postgres/postmaster.pid": Permission denied

I also tried to re-run the initdb command, but ran into a similar problem:

initdb: could not access directory "/usr/local/var/postgres": Permission denied

If it matters, PostgreSQL was installed via Homebrew. Running brew info postgresql yields the expected results (version, summarized docs).

Danijel
  • 488
  • 5
  • 14
Jon
  • 131
  • 1
  • 1
  • 4
  • http://stackoverflow.com/questions/6770649/repairing-postgresql-after-upgrading-to-osx-10-7-lion – Matt Ball Jul 26 '11 at 17:41
  • http://stackoverflow.com/questions/6814127/lion-update-removed-the-postgres-user-how-to-restore-it – Denis de Bernardy Jul 26 '11 at 17:45
  • Matt - Yeah, I saw that question, but I don't believe it's a path issue. Running `which psql` yields `/usr/local/bin/psql`, which should be the correct Homebrew path. I already have the proper path export set in .bash_login. Also, my issue is with starting the server, not connecting. – Jon Jul 26 '11 at 17:49
  • Those questions don't deal with a "path issue". They deal with a permission issue, because the postgres user got removed –  Jul 26 '11 at 17:51
  • The first question deals (mostly) with paths, the second with the postgres user being removed. Homebrew seemed to be hosed as well, so I'm going to uninstall/re-install and see if that works. – Jon Jul 26 '11 at 19:19

3 Answers3

8

Well, it turns out the solution was pretty simple. I changed the group on /usr/local/var to staff (from wheel) and changed the ownership (chown -R) to my system account (from root).

After that, postgres started up fine.

I was a little nervous changing those permissions, but the only thing in my /usr/local/var was a postgres directory, so all should be well. If you have other directories/files in /usr/local/var, maybe don't use the -R flag when chown'ing?

The Homebrew ruby installer script changes the group of /usr/local/var to staff, so that must have gotten undone when upgrading to Lion. Not sure about the ownership being root instead of my system account though...

Jon
  • 131
  • 1
  • 1
  • 4
  • just do be sure: you did `chgrp -R staff /usr/local/var` and `chown -R [username here] /usr/local/var`, right? – DerZyklop Mar 08 '17 at 11:21
0

sudo chown -R $(whoami) /usr/local/var

Kirti
  • 41
  • 2
0

I faced a similar issue, after I've checked I noticed that brew installed postgres on a different path and it is called postgresql@14 (version can be changed).

(used brew & M1 chip)

this made the trick:

pg_ctl -D /opt/homebrew/var/postgresql@14 start
Tomer S
  • 900
  • 1
  • 10
  • 21