How To Download And Configure PostgreSQL For Rails On Your Mac

3 Aug

If you’ve played around with Ruby on Rails, you might have noticed that Rails comes with SQLite3 as your test / development database, while Heroku defaults to PostgreSQL in production.

This is not surprising, considering how hard it is to install PostgreSQL compared to SQLite3. However, since you’re not testing / developing in completely the same environment as production, you’re putting yourself in a position for some possibly nasty surprises (in case you can’t tell, I’ve definitely faced these already, even with my small apps!).

Luckily, there is now a simpler way to install and configure PostgreSQL if you haven’t ever downloaded it on your Mac before brought you by Ruby on Rails developer Gavin Morgan:

Here are the steps to follow to get PostgreSQL downloaded and running with your Rails application:

  1. Visit postgresapp.com & download the app.
  2. Install & run the app.
  3. Execute “$ psql -h localhost” to enter local psql terminal.
  4. Execute “=# select * from pg_roles;” to list the accounts w/ access privelages.
  5. Execute “$ rails new myApp -d postgresql” to create psql rails app.
  6. Fix config/database.yml to include your psql credentials — ‘username‘and ‘password’ (you can leave the password blank if you don’t remember it).
  7. Fit ‘host: localhost‘ into config/database.yml under ‘test:’ & ‘development:
  8. Note: Heroku is gonna throw database.yml away & use its own settings.
  9. Execute “$ rake db:create:all” to create your psql databases.

Note: If you have installed PostgreSQL before via ‘$brew install postgresql’ and it’s not working for you, find someone more experienced to help you make it work. Today, I got help from bloc.io co-founder Dave Paolo, who performed a lot of magic and sorcery to delete the installed version of PostgreSQL from my machine so I can re-download it!

Advertisements

One Response to “How To Download And Configure PostgreSQL For Rails On Your Mac”

  1. SutoCom August 12, 2012 at 4:19 pm #

    Reblogged this on Sutoprise Avenue, A SutoCom Source.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s