3
votes

I've been googling around for tutorials on how to use Ruby on Rails with PostgreSQL. There is some pretty good info out there, but almost every guide is focused on how to configure Rails to use Postgres in development and test environments. They will warn you not to use these configurations for production, but not mention what you should do instead.

On the Postgres side, I would like to know what role I need to give to the Postgres user that Rails will connect to the database with. Also, I assume I would use environment variables in Rails for the DB credentials. Should I use ENV['DATABASE_URL'] in my database.yml? What does this pattern typically look like?

I'm using Rails 4.1.0 with PostgreSQL 9.1.13 on Ubuntu 12.04.2.

1

1 Answers

2
votes

I recommend the gem figaro to manage your environment variables.

Where are you hosting your app? In Heroku you just need to set your database.yml like this:

production:
   adapter: postgresql
   encoding: unicode
   database: yourappname_production
   pool: 5
   username: root
   password: 

And you should have these gems added to your Gemfile:

gem 'pg'
gem 'activerecord-postgresql-adapter'

then you just deploy and everything is set for you.

Hope it helps