0

ETA: The possible answer above does NOT answer my question. I'm unable to create those directories.

After a trip to the Apple Store for repairs, my macbook came back upgraded with Yosemite. My dev environment is working fine EXCEPT for Postgres. I reinstalled with homebrew and when I type "psql" into my terminal I get this:

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

I've tried pretty much every suggestion on the site to no avail. Whenever I try to change anything, I get permission denied and it doesn't work even with a SUDO.

Some things I've tried:

$pg_ctl initdb

Result:

The files belonging to this database system will be owned by user "**********". This user must also own the server process.

The database cluster will be initialized with locale "en_US.UTF-8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /var/lib/pgsql/data ... initdb: could not create directory "/var/lib/pgsql": Permission denied pg_ctl: database system initialization failed

I've tried using Lunchy

$ lunchy start postgres /usr/local/Cellar/postgresql/9.4.0/homebrew.mxcl.postgresql.plist: File exists started homebrew.mxcl.postgresql

Didn't work.

Tried this too:

$ ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents ‘/Users/**************/Library/LaunchAgents/homebrew.mxcl.postgresql.plist’ -> ‘/usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist’

And a few other methods.

Postgres is located here: /usr/local/bin/postgres on my computer. Should it be moved?

Does anybody have any step by step instructions I can try? I feel like I've tried everything and I'm really at a loss here because it shouldn't be this difficult. Thanks!

awuseda
  • 1
  • 3
  • 1
    I think [this answer](http://stackoverflow.com/a/26001639/2456549) should help you resolve your issue. – Justin Jan 26 '15 at 04:03
  • Thanks for the quick response. Got permission denied when i tried to make the directories and it didn't work even with a sudo. For whatever reason I cannot create those directories. – awuseda Jan 26 '15 at 04:16
  • Postgres as installed by Homebrew puts its files into `/usr/local/var/postgres`, not into `/var/lib`. You might have installed Postgres twice, once through Homebrew, once by other means (Macports? Some binary installer like EnterpriseDB?). Make sure `which pg_ctl` returns `/usr/local/bin/pg_ctl`. If it does not, run `/usr/local/bin/pg_ctl` directly, or better, remove the second installation of Postgres. – janfoeh Jan 26 '15 at 09:35
  • Please add the *full* output of `/usr/local/bin/pg_config` to your question. – janfoeh Jan 26 '15 at 18:59
  • @janfoeh thank you so much for all your help thus far `/usr/local/var/postgres` does exist as a directory, when i run `pg_ctl start -D /usr/local/var/postgres` it gives me `pg_ctl: could not open PID file "/usr/local/var/postgres/postmaster.pid": Permission denied` then when I sudo I get `pg_ctl: cannot be run as root`. I'm not sure how to check the sever.log in that directory for errors, unfortunately my dev environment was set up for me and I'm learning this now as I go along – awuseda Jan 26 '15 at 22:58
  • No problem. Find out your OS X username - if you don't know, run `whoami`. Then, run `chown -R username /usr/local/var/postgres`, with "username" replaced with your own username. That should fix the permission error; try `pg_ctl start -D /usr/local/var/postgres` again. – janfoeh Jan 26 '15 at 23:28
  • Sorry: it should be `sudo chown -R username /usr/local/var/postgres` – janfoeh Jan 27 '15 at 00:02
  • @janfoeh okay after running that I got `pg_ctl: directory "/usr/local/var/postgres" is not a database cluster directory` – awuseda Jan 27 '15 at 01:41
  • Let's get the old database directory out of the way with `sudo mv /usr/local/var/{postgres,old-postgres}`. Create a fresh database directory with `/usr/local/bin/initdb -D /usr/local/var/postgres`. Try starting the server again with `/usr/local/bin/pg_ctl start -D /usr/local/var/postgres`. – janfoeh Jan 27 '15 at 08:20
  • @janfoeh after `sudo mv /usr/local/var/{postgres,old-postgres}` nothing appears to happen. when I run `/usr/local/bin/initdb -D /usr/local/var/postgres` I get the following... – awuseda Jan 27 '15 at 13:14
  • `The files belonging to this database system will be owned by user "***". This user must also own the server process. The database cluster will be initialized with locale "en_US.UTF-8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. fixing permissions on existing directory /usr/local/var/postgres ... initdb: could not change permissions of directory "/usr/local/var/postgres": Operation not permitted'` – awuseda Jan 27 '15 at 13:15
  • Let's try setting the permissions on the parent directory then. Run `sudo chown -R username /usr/local/var` (with "username" again replaced with your own, real username, as found through `whoami`). Then try the `i/usr/local/bin/initdb -D /usr/local/var/postgres` again. – janfoeh Jan 27 '15 at 14:03
  • @janfoeh `The files belonging to this database system will be owned by user "" This user must also own the server process. The database cluster will be initialized with locale "en_US.UTF-8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. initdb: directory "/usr/local/var/postgres" exists but is not empty If you want to create a new database system, either remove or empty the directory "/usr/local/var/postgres" or run initdb with an argument other than "/usr/local/var/postgres".` – awuseda Jan 27 '15 at 19:24
  • @janfoeh just checking to see if you have any further insight on this. If not, its quite fine, thank you so much for walking me through it. Much appreciated! – awuseda Jan 30 '15 at 03:10
  • I don't get why you say that moving `/usr/local/var/postgres` away didn't do anything, but `initdb` complains that the directory already exists. Does it exist? What's in there? – janfoeh Jan 30 '15 at 09:48
  • @janfoeh thanks for responding. it does exist. only the server.log is in there at the moment – awuseda Jan 30 '15 at 12:19
  • Ah, I suspect that there's still a postgres process running that recreates that directory. Try `ps aux | grep post`; there should be five postgres processes listed. Look for the one that has `postgres -D` in it, note its PID (second column), and kill that PID with `kill `. Check again with the `ps aux` command after a minute. If it has come back, it was probably started through launchd. In that case, try `launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist`. Remove the stubborn directory, and try the initdb command again. – janfoeh Jan 30 '15 at 12:39
  • @janfoeh there are 5 directories but none seem to have postgres-D in it: – awuseda Jan 30 '15 at 20:39
  • link to screenshot: [link](http://i60.tinypic.com/2hgwq2p.jpg) – awuseda Jan 30 '15 at 20:47
  • Then I'm out of ideas - sorry° – janfoeh Jan 30 '15 at 21:40
  • @janfoeh totally understandable. Thank you for everything! – awuseda Jan 31 '15 at 01:13

1 Answers1

0

I just fixed this issue myself with the help of CoderWall. My problem was some missing directories in /usr/local/var/postgres/

The one-line fix supplied from CoderWall:

mkdir -p /usr/local/var/postgres/{pg_tblspc,pg_twophase,pg_stat_tmp}

I tagged a sudo to the begining of mine just to make sure it work.

Jeremy
  • 1,201
  • 12
  • 18