0

Trying to build a Rails project but when I go to create a db I get this error:

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 uninstalled the pg gem and reinstalled it but I am still getting the error.

Any thoughts on how to resolve this issue?

Resolution:

First Way

I can't up vote yet but the solution that worked for me was to run:

pg_ctl -D /usr/local/var/postgres stop -s -m fast

and then to:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

I am now able to create a db in my rails app.

Thanks @Panayoitis Georgiou (&everyone)!

Second way

If you want to manually start and stop postgresql (installed via homebrew), the easiest way is:

brew services start postgresql

and

brew services stop postgresql

AmeliaK
  • 21
  • 5
  • i think, u have to run your pg server ! Try this one and let me know: `pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start` – 7urkm3n May 03 '16 at 17:24
  • If you are on a Mac, you can get a self-contained Postgres DB/app from http://postgresapp.com/. Once installed, it runs like any other app. Easy way to get going with PG. But, as 7urkm3n noted, you need to have your DB server running in order to create the DB. – craig.kaminsky May 03 '16 at 17:30

2 Answers2

1

Run this command to manually start the server:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

if that is not woking try the following

For pure installing postgresql on Mac OS, the process will be (using brew command):

brew install postgresql

then if you want to automatically run postgresql at login:

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

or else you just want to run it anytime you want:

postgres -D /usr/local/var/postgres

If your case is more complicated, let's brew uninstall postgresql and redo these steps.

Hope it helps!

Panayiotis Georgiou
  • 1,135
  • 3
  • 19
  • 36
  • Thanks for the above suggestions. When I try to manually start the server I get this: `pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start pg_ctl: another server might be running; trying to start server anyway server starting` but I dont have any other servers running – AmeliaK May 03 '16 at 17:37
  • try this pg_ctl -D /usr/local/var/postgres stop -s -m fast – Panayiotis Georgiou May 03 '16 at 17:39
  • also initdb /usr/local/var/postgres -E utf8 – Panayiotis Georgiou May 03 '16 at 17:40
1

I can't up vote yet but the solution that worked for me was to run:

pg_ctl -D /usr/local/var/postgres stop -s -m fast

and then to:

pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

I am now able to create a db in my rails app.

Thanks @Panayoitis Georgiou (&everyone)!

AmeliaK
  • 21
  • 5
  • Welcome to SO. Glad you made it. Don't forget to mark the answers 'accepted' that worked for you ;) – uday May 03 '16 at 17:59