Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I currently have Ruby on Rails installed via RVM in Ubuntu 12.04. The default database is set up in SQLite3, but I'd like to switch to PostgreSQL for the purposes of pushing to Heroku. How can I accomplish this?

share|improve this question

1 Answer

up vote 57 down vote accepted

Here are the steps I followed:

Install PostgreSQL and development package

$ sudo apt-get install postgresql-9.1
$ sudo apt-get install libpq-dev

Set up a user that is the same as my Ubuntu log-in

$ sudo su postgres -c psql
postgres=# CREATE ROLE <username> SUPERUSER LOGIN;
postgres=# \q

Modify Gemfile

# Remove gem 'sqlite3'
gem 'pg'

Modify database.yml in app directory

development:
  adapter: postgresql
  encoding: unicode
  database: appname_development
  pool: 5
  timeout: 5000
  username: <username>
  password:

test:
  adapter: postgresql
  encoding: unicode
  database: appname_test
  pool: 5
  timeout: 5000
  username: <username>
  password:

Run bundle install

$ bundle install

Create databases and migrations

$ rake db:create:all
$ rake db:migrate

Here are the sources I used to help:
http://mrfrosti.com/2011/11/postgresql-for-ruby-on-rails-on-ubuntu/
http://railscasts.com/episodes/342-migrating-to-postgresql
https://devcenter.heroku.com/articles/local-postgresql

share|improve this answer
7  
If you want to add a password use this command after running CREATE ROLE: ALTER ROLE <username> WITH PASSWORD '<yourpassword>'; then obviously add your password into database.yml – Hengjie Jan 24 at 5:33
4  
Alternatively, if you're just creating the role for the first time and want to enter in a password as well: CREATE ROLE <username> SUPERUSER LOGIN PASSWORD '<yourpassword>'; – Hengjie Jan 24 at 5:40
If you set the user as identical with your unix username, is this secure even if there is no password? Based on, e.g., the mrfrosti.com link above, and also Heroku's Postgress.app, it seems like that's often the suggested route. – Dav Clark Feb 5 at 17:02
here's instructions for installing 9.2 on ubuntu askubuntu.com/questions/186610/how-do-i-upgrade-to-postgres-9-2/… – Danny Feb 18 at 17:30
FATAL: Peer authentication failed for user "awesome" – jmontross May 9 at 4:38
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.