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.
The Cause
Lion comes with a version of postgres already installed and uses those binaries by default. In general you can get around this by using the full path to the homebrew postgres binaries but there may be still issues with other programs.
The Solution
curl http://nextmarvel.net/blog/downloads/fixBrewLionPostgres.sh | sh
Via
http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/
for what it's worth, I experienced this same error when I had a typo (md4
instead of md5
) in my pg_hba.conf
file (/etc/postgresql/9.5/main/pg_hba.conf
)
If you got here as I did, double-check that file once to make sure there isn't anything ridiculous in there.
If you are running Homebrew, uninstall Postgresql end pg gems:*
$ gem uninstall pg
$ brew uninstall postgresql
Download and run the following script to fix permission on /usr/local:* https://gist.github.com/rpavlik/768518
$ ruby fix_homebrew.rb
Then install Postgres again and pg gem:*
$ brew install postgresql
$ initdb /usr/local/var/postgres -E utf8
To have launchd start postgresql at login run:
$ ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Or start manually.
Install pg gem
$ gem install pg
I hope have helped
One of the reason could be that
unix_socket_directories in postgresql.conf file is not listed with the directory it is looking for.
In the question example it is looking for directory /tmp this has to be provided in the postgresql.conf file
something like this:
unix_socket_directories = '/var/run/postgresql,/tmp' # comma-separated list of directories
This solution worked for me.
I encountered this error when running on Mac 10.15.5 using homebrew and seems to be a more updated solution that works where the ones above did not.
There is a file called postmaster.pid which should is automatically deleted when postresql exits.
If it doesn't do the following
for me command rm /usr/local/var/postgres/postmaster.pid
didn't work cause I installed a specific version of postgresql with homebrew.
the right command is rm /usr/local/var/postgres@10/postmaster.pid
.
then brew services restart postgresql@10
.