Like some others I am getting this error when I run rake db:migrate in my project or even try most database tasks for my Ruby on Rails 3.2 applications.
I had that problem when I upgraded Postgres to 9.3.x. The quick fix for me was to downgrade to whichever 9.2.x version I had before (no need to install a new one).
$ ls /usr/local/Cellar/postgresql/
9.2.4
9.3.2
$ brew switch postgresql 9.2.4
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
<open a new Terminal tab or window to reload>
$ psql
"Homebrew install specific version of formula?" offers a much more comprehensive explanation along with alternative ways to fix the problem.
I had PostgreSQL 9.3 and got the same error,
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 fixed this using:
chmod 777 /var/lib/pgsql/9.3/data/pg_hba.conf
service postgresql-9.3 restart
It works for me.
Check there is no postmaster.pid in your postgres directory, probably /usr/local/var/postgres/
remove this and start server.
Check - https://github.com/mperham/lunchy is a great wrapper for launchctl.
So for a lot of the issues here, it seems that people were already running psql and had to remove postmaster.pid
. However, I did not have that issue as I never even had postgres installed in my system properly.
Here's a solution that worked for me in MAC OSX Yosemite
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
Hope this helps! Toodles!
Also, this answer helped me the most: https://stackoverflow.com/a/21503349/3173748
I don't really know Mac or Homebrew, but I know PostgreSQL very well.
You want to figure out where the logs are from PostgreSQL trying to start and what the socket directory is for PostgreSQL. By default when you build PG, the socket directory is /tmp/. If you didn't change that when you built PG and then you started PG, you should be able to see a socket file in /tmp if you do: ls -al /tmp
The socket file starts with a ".", so you won't see it with the '-a' to ls.
If you don't see a socket there, and you don't see anything from ps awux | grep postgres, then PG is probably not running, or maybe it is and it's the OSX-installed one. What might be happening is that you might be getting a conflict on listening on port 5432 on localhost- use netstat -anp to see what, if anything, is listening on 5432. If a Mac OSX PG is already listening on that port then that might be the problem.
Hope that helps. I have heard that homebrew can make things a bit ugly and a lot of people I've talked to encourage using a VM instead.
Hello world :)
The best but strange way for me was to do next things.
1) Download postgres93.app or other version. Add this app into /Applications/ folder.
2) Add a row (command) into the file .bash_profile
(which is in my home directory):
export PATH=/Applications/Postgres93.app/Contents/MacOS/bin/:$PATHIt's a PATH to
psql
from Postgres93.app
. The row (command) runs every time console is started.
3) Launch Postgres93.app
from /Applications/
folder. It starts a local server (port is "5432" and host is "localhost").
4) After all of this manipulations I was glad to run $ createuser -SRDP user_name
and other commands and to see that it worked! Postgres93.app
can be made to run every time your system starts.
5) Also if you wanna see your databases graphically you should install PG Commander.app
. It's good way to see your postgres DB as pretty data-tables
Of, course, it's helpful only for local server. I will be glad if this instructions help others who has faced with this problem.