I have a Postgresql installed via Homebrew and after a crash I can not start server anymore..
if I do
$ pg_ctl start
I get
pg_ctl: no database directory specified and environment variable PGDATA unset
If I do
$ pg_ctl -D /Library/PostgreSQL/data start
I get
pg_ctl: could not open PID file "/Library/PostgreSQL/data/postmaster.pid": Permission denied
Everything was working just fine and then.. out of the blue, this.
The data folder above has permissions set at “Everything” for postgres user and “None” for everyone..
Path looks fine (in my ~/.bash_profile)
export PATH=/usr/local/bin:$PATH
When you first started Pg, did you let homebrew start it for you, or did you manually start it with
pg_ctl? I ask because I’m guessing you probably need to start and stop Pg using homebrew scripts and/or usinglaunchdrather than directly viapg_ctl. I don’t use homebrew (or Mac OS X much) but a quick search suggests that homebrew installs of Pg are usually started and stopped vialaunchdand~/Library/LaunchAgents/org.postgresql.postgres.plist.If you want to manage it manually:
What user does homebrew usually run PostgreSQL as? If you’re launching Pg via
pg_ctlyou need to run it as the right user. From vague memory of other discussion I’ve seen about homebrew here, it’s probably a user namedpostgresorpostgres_. Double-check using:and see what the owning user is, then run:
… replacing “postgres_” with the owner of the datadir.
I suspect the reason you’re getting permissions errors is that you probably didn’t recursively apply the changes. Please don’t; run Pg as the correct user instead.