Get Rails working with Postgresql

July 14, 2014

Tonight I was banging my head against the wall trying to get my Rails application to use Postgres for Test and Development.

Initially, I thought “sure no problem how hard could this be.” I read up in my copy of The Rails 4 Way which had most of the configuration I needed. Here was me doing a happy dance that I was able to cross off 1 of the exercises from the Ruby on Rails Tutorial man I was super excited.

So I filled in the yaml and ran

$ rake db:setup

The message I got was a BIG


I thought okay this can’t be this hectic and started searching and searching and searching. I re-read the error message, and it was complaining something along the lines of “is postgresql installed?”

At that point, I decided “screw this” and went for a walk. When I got back home I decided to have another bash. I tried to find any page or post that had the different variables applicable in a database.yml file and found nothing.

Then on a whim I decided to add

host: localhost


$ rake db:setup

It worked!!! So again I am going to post my configuration so that if anyone ever (even me) runs into this there is a solution to getting Postgresql working with your Rails environment.

Here is my database.yml file

default: &default
  host: localhost
  adapter: postgresql
  encoding: unicode
  pool: 5
  username: postgres
  password: work!1234

  <<: *default
  database: sample_app_dev
  <<: *default
  database: sample_app_test

Discussion, links, and tweets

My name is Deon Heyns and I am a developer learning things and documenting them in realtime. Python, Ruby, Scala, .NET, and Groovy are all languages I have written code in. I appeared in the New York Post once. I host my code up at GitHub and Bitbucket so have a look at my code, fork it and send those pull requests.

comments powered by Disqus