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.
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