ruby-on-railspostgresqlubuntupostgresql-9.1rails-postgresql

How to set up Postgres database for local Rails project?


I recently got a new machine and would now like to work on my projects from Github. I'm curious as to how to properly set up the Postgres database on my local machine. I have postgresql, pgadmin3 and libpq-dev installed on Ubuntu (12.04).

I pull down the project:

git clone https://github.com/thebenedict/cowsnhills.git

and run:

bundle.

When I run:

rake db:create && rake db:schema:load

I get this error:

rake db:create && rake db:schema:load
FATAL:  password authentication failed for user "cnh"
FATAL:  password authentication failed for user "cnh"
....

The config/database.yml file looks like this:

development:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: cnh_development
  pool: 5
  username: cnh
  password: cnh

test:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: cnh_test
  pool: 5
  username: cnh
  password: cnh

production:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: cnh_production
  pool: 5
  username: cnh
  password: cnh

What's the proper way to set up the Postgres database so I can run this project on my local machine?

Right now when I start the Rails server I get:

enter image description here


Solution

  • firstly, install postgresql
    sudo add-apt-repository ppa:pitti/postgresql
    sudo apt-get update
    
    #now install postgresql
    sudo apt-get install postgresql-9.1 libpq-dev
    
    create a new user in psql
    sudo su postgres
    createuser user_name #Shall the new role be a superuser? (y/n) y
    
    Gemfile
    gem 'pg'
    

    bundle install

    development.yml
    development:
      adapter: postgresql
      database: app_development
      pool: 5
      username: user_name
      password: