14

I am trying to deploy to heroku.

Rails 3.1.0.rc4,

I get the following error from Heroku logs:

Starting process with command: `thin -p 48902 -e production -R /home/heroku_rack/heroku.ru start`
2011-06-20T11:25:44+00:00 app[web.1]: /app/.bundle/gems/ruby/1.9.1/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `rescue in establish_connection': Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.) (RuntimeError)

I tried to install the activerecord-postgresql-adapter but then I get this error:

Could not find gem 'activerecord-postgresql-adapter (>= 0)' in any of the gem sources listed in your Gemfile.

So I tried to add this to my gem file

gem 'pg'

which produced this error:

Installing pg (0.11.0) with native extensions /Users/imac/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:533:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)

any ideas?

chell
  • 7,646
  • 16
  • 74
  • 140
  • I've seen that error locally when I set the adapter to postgres instead of postgresql in database.yml but since Heroku rewrites the database.yml on deployment I don't think that's the problem here. Are you using Cedar stack by any chance? If you don't have Postgresql installed locally then that will explain the last error since you need it installed to install the gem locally. – John Beynon Jun 20 '11 at 12:02

3 Answers3

18

You don't have to install Postgres locally. In your Gemfile, put 'pg' in group :production, as johnny-grass suggests, and then when you run bundle, just specify --without production, like this:

bundle --without production

Unfortunately, you have to remember this argument when you run bundler, but at least you don't have to install and maintain postgres locally.

Please note that Heroku "strongly recommends against" using sqlite, saying that "Your production and development environment should be as close to identical as possible" http://devcenter.heroku.com/articles/rails3

Jared Beck
  • 16,796
  • 9
  • 72
  • 97
12

Do you have PostgreSQL installed on your computer? If you don't then install it first, then install the pg gem.

# gemfile
group :production do
  gem 'therubyracer-heroku', '0.8.1.pre3' # you will need this too
  gem 'pg'
end
David
  • 7,310
  • 6
  • 41
  • 63
  • I do not have PostgreSQL on my system. I will follow your instructions and hope for the best. Thanks for the advise. – chell Jun 21 '11 at 10:11
  • 2
    With help from [this article](http://stackoverflow.com/questions/4827092/unable-to-install-pg-gem), the following worked for me on Ubuntu: `sudo apt-get install postgresql` followed by `sudo apt-get install libpq-dev`. Also, therubyracer 0.9.4 seems to compile fine on Heroku--I did not need `'therubyracer-heroku'`. – Mark Berry Oct 05 '11 at 00:42
6

I found a solution in this Heroku article.

As Jared said, they suggest to create a different group for postgresql.

PaquitoSoft
  • 3,177
  • 6
  • 29
  • 32