0

I am new to Ruby on rails. I've created basic demo apps by tutorial learning by examples.

First it working fine, one week later i got error when type rails s,

Error

PG::ConnectionBad
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 am using PostgreSQL database.

I am on MAC OS X 10.8.5

I have found similar questions on SO, but they are experiencing at some advance stage and thus involves some advance solutions.

when type

which psql
/usr/local/bin/psql
Mary Smith
  • 121
  • 2
  • 10

2 Answers2

1

It seems upgrading your OS has changed the permissions on the directory where Postgres keeps its data.

Run

sudo chown -R sabir:staff /usr/local/var/postgres

to make your user account the owner of that directory. Enter your password when it asks for it; you will not see the characters as you enter them.

The homebrew version of Postgres includes the ability to start automatically. To check whether your installation does, run

ls -l ~/Library/LaunchAgents/

You should see a line ending with homebrew.mxcl.postgresql.plist. If you do not see this line, run

ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

in order to have it start automatically.

Finally, run

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

to make sure Postgres is active now. Confirm by typing

psql -l
janfoeh
  • 10,243
  • 2
  • 31
  • 56
  • when i type `launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist` – Mary Smith Feb 17 '15 at 14:40
  • `launchctl: Dubious permissions on file (skipping): /Users/Sabir/Library/LaunchAgents/homebrew.mxcl.postgresql.plist nothing found to unload` – Mary Smith Feb 17 '15 at 14:40
  • Did you execute the second command, `launchctl load`? Does `psql -l` work? If not, please post the output of `ls -lh ~/Library/LaunchAgents` – janfoeh Feb 17 '15 at 14:43
  • output of `ls -lh ~/Library/LaunchAgents` `total 40 -rw-r--r-- 1 Sabir staff 697B 12 Dec 10:43 com.adobe.AAM.Updater-1.0.plist -rw-r--r-- 1 Sabir staff 425B 5 Jan 22:53 com.apple.FolderActions.enabled.plist -rw-r--r-- 1 Sabir staff 517B 17 Feb 08:22 com.apple.FolderActions.folders.plist -r-xr-xr-x 1 Sabir staff 457B 10 Dec 21:39 com.citrixonline.GoToMeeting.G2MUpdate.plist lrwxr-xr-x 1 Sabir staff 56B 17 Feb 20:11 homebrew.mxcl.postgresql.plist -> /usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist` – Mary Smith Feb 17 '15 at 14:45
  • `launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist` out is `launchctl: Dubious permissions on file (skipping): /Users/Sabir/Library/LaunchAgents/homebrew.mxcl.postgresql.plist nothing found to load` – Mary Smith Feb 17 '15 at 14:46
  • Okay. Please run `sudo chown Sabir:staff /usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist`, and try launctl load again. – janfoeh Feb 17 '15 at 14:48
  • same problem, when i run `launchctl unload` – Mary Smith Feb 17 '15 at 14:51
  • 'launchctl: Dubious permissions on file (skipping): /Users/Sabir/Library/LaunchAgents/homebrew.mxcl.postgresql.plist nothing found to unload' – Mary Smith Feb 17 '15 at 14:51
  • Okay, but what about `load`? – janfoeh Feb 17 '15 at 14:54
  • `launchctl: Dubious permissions on file (skipping): /Users/Sabir/Library/LaunchAgents/homebrew.mxcl.postgresql.plist nothing found to load` – Mary Smith Feb 17 '15 at 14:55
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/71087/discussion-between-janfoeh-and-mary-smith). – janfoeh Feb 17 '15 at 14:57
0

When you install postgres using homebrew, than maybe you just started it manually in foreground. So after closing the terminal window postgres was not running anymore.

I'd suggest to do the following steps:

  • Check if postgres is running by grepping the process list: ps aux | grep postgres
  • if it's running try to sudo kill -9 {POSTGRES_PID}
  • if not running, use brew info postgres to see how to start it manually (or on startup etc.)
  • start postgres with the result from homebrew - in my case postgres -D /usr/local/var/postgres

I hope, that will help you out. If you installed postgres on another basis, I can change my answer accordingly.

ernd enson
  • 1,764
  • 1
  • 14
  • 29
  • postgres -D /usr/local/var/postgres FATAL: data directory "/usr/local/var/postgres" has wrong ownership HINT: The server must be started by the user that owns the data directory. – Mary Smith Feb 17 '15 at 13:18
  • @MarySmith please run `ls -l /usr/local/var/postgres` and tell us the result. Also, please run `whoami`, which returns your Mac username. – janfoeh Feb 17 '15 at 13:38
  • run `ls -l /usr/local/var/postgres` `total 1288 -rwxrwxrwx 1 root wheel 4 28 Aug 15:22 PG_VERSION drwxrwxrwx 51 root wheel 1734 28 Nov 16:42 base drwxrwxrwx 43 root wheel 1462 23 Jan 10:26 global drwxrwxrwx 3 root wheel 102 28 Aug 15:22 pg_clog -rwxrwxrwx 1 root wheel 4467 28 Aug 15:22 pg_hba.conf -rwxrwxrwx 1 root wheel 1636 28 Aug 15:22 pg_ident.conf drwxrwxrwx 4 root wheel 136 28 Aug 15:22 pg_multixact drwxrwxrwx 3 root wheel 102 23 Jan 10:25 pg_notify ---------- ----- ` – Mary Smith Feb 17 '15 at 13:43
  • run whoami display my username – Mary Smith Feb 17 '15 at 13:43
  • @MarySmith I know, but I need to know your username :) Also, could you please write @ janfoeh (without the space) when you answer my comments? That way, SO notifies me of your reply. – janfoeh Feb 17 '15 at 13:49
  • @janfoeh my username is `sabir` – Mary Smith Feb 17 '15 at 14:12