1

When I try to connect server to create database. I am getting this error.

Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "host"=>"localhost", "socket"=>"/var/run/postgresql/.s.PGSQL.5432", "pool"=>5, "min_messages"=>"error", "database"=>"rails_contributors_test"}
-- enable_extension("plpgsql")
rake aborted!
PG::ConnectionBad: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?

I tried a lot but didn't get success. Looking for help.

Postgres version I have as

which postgres
=> /usr/local/bin/postgres
postgres --version
=> postgres (PostgreSQL) 9.4.4
1
  • You need to answer the question in the error message. Have you started the server? Installing it isn't enough. On my mac, the command is pg_ctl -D /usr/local/var/postgres start. But I'm running 9.4.1 at the moment, and the database path can vary. Commented Sep 4, 2015 at 3:53

1 Answer 1

9

Try installing Postgres.app on your Mac OSX.

and start the postgres i.e. click on Open psql.

Then, restart the rails server.

After this, it should fix your issue.

Update (If the above does not work)

  • To fix the issue, remove the PID file. Find the postgres data directory. On Mac OSX using homebrew it is /usr/local/var/postgres/.

  • To make sure this is the problem, look at the log file (server.log). On the last lines you will see: FATAL: lock file "postmaster.pid" already exists HINT: Is another postmaster (PID 347) running in data directory "/usr/local/var/postgres"?

  • If so, rm postmaster.pid

  • Restart your server. On Mac OSX, do:

    launchctl unload homebrew.mxcl.postgresql.plist
    launchctl load -w homebrew.mxcl.postgresql.plist

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.