In Rails, Couldn't create database for {“adapter”=>“postgresql”,

前端 未结 9 2030
醉话见心
醉话见心 2020-12-14 03:34

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

相关标签:
9条回答
  • 2020-12-14 03:56

    I encountered an identical issue and was able to solve the error by:

    1. using postgresapp.com (recommended by heroku in https://devcenter.heroku.com/articles/heroku-postgresql#local-setup),
    2. adding to config/database.yml

      host: localhost
      
    3. 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
      
    0 讨论(0)
  • 2020-12-14 03:57

    The answer from zquintana above worked for me with a few small caveats.

    My solution (using Homebrew):

    1. If you have the gem installed gem uninstall pg
    2. Remove old copy of postgresql brew uninstall postgresql
    3. Re-install postgresql brew install postgresql
    4. The install notes mention:

    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

    1. So run ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

    2. Then launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

    3. Now re-install the gem with the Homebrew configs gem install pg -- --with-pg-config=/usr/local/bin/pg_config

    4. Now run your rake db:create

    0 讨论(0)
  • 2020-12-14 04:03

    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!

    0 讨论(0)
  • 2020-12-14 04:04

    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:

    1. Make sure that all binaries are pointing to binaries in Cellar directory (/usr/local/Cellar on Mac OS X)
    2. Uninstall pg gem gem uninstall pg
    3. Reinstall with Homebrew configs 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!

    0 讨论(0)
  • 2020-12-14 04:05

    Simple add host: localhost to your database.yml

    For more detail please visit rake db:create:all fails to connect to PostgreSQL database

    0 讨论(0)
  • 2020-12-14 04:06

    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.

    0 讨论(0)
提交回复
热议问题