I\'m trying to run rake db:create
or rake db:setup
but I get the following error. It\'s strange because rake db:create
it\'s working f
I encountered an identical issue and was able to solve the error by:
adding to config/database.yml
host: localhost
resetting shared memory settings as recommended in troubleshooting section of http://postgresapp.com/documentation:
sudo sysctl -w kern.sysv.shmall=65536
sudo sysctl -w kern.sysv.shmmax=16777216
The answer from zquintana above worked for me with a few small caveats.
My solution (using Homebrew):
gem uninstall pg
brew uninstall postgresql
brew install postgresql
To have launchd start postgresql at login:
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then to load postgresql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Or, if you don't want/need launchctl, you can just run:
postgres -D /usr/local/var/postgres
So run ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
Then launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Now re-install the gem with the Homebrew configs gem install pg -- --with-pg-config=/usr/local/bin/pg_config
Now run your rake db:create
First, you will need to create your user manually in Postgres, while granting privilege of database creation (AKA createdb) for this user.
To do so, first, open Postgres shell prompt
$ sudo -u postgres psql
Create your user
postgres=# create role Your_DB_username with createdb login password 'YOUR_PASSWORD';
Exit from Postgres shell
postgres=# \q
Do whatever db-related rake task:
$ rake db:create
And it will work!
I installed PG on Mac OS X via Homebrew (I didn't realize it came default in Mac OS X), and had the same problem. I may have made the problem worse by installing the pg gem before installing pg via Homebrew.
I solved this same problem by doing the following:
gem uninstall pg
gem install pg -- --with-pg-config=/usr/local/bin/pg_config
(if you created a rails project with pg setup, this is explained in your database.yml config file)And it worked!
Simple add host: localhost
to your database.yml
For more detail please visit rake db:create:all fails to connect to PostgreSQL database
Solved!
Solution was simple to update current installed gems.
Another solution to try is set host: localhost
or whatever host you use on development settings on database.yml file.