59

Running a Ruby on Rails (RoR) app or Ruby code which uses the ActiveRecord framework, you get the error message:

Please install the postgresql adapter: gem install activerecord-postgresql-adapter

Trying to run:

gem install activerecord-postgresql-adapter

also fails, leaving you at a loss.

2
  • You could read the following post to get an idea. Commented Nov 2, 2009 at 23:28
  • My attempts at following that post are included in my original answer, as they did not work for me. Commented Nov 2, 2009 at 23:32

9 Answers 9

128

The problem is not what anyone wrote. The problem is that the name of the postgresql database adapter is "postgresql", not "postgres", though the name of the GEM is "pg".

The definition in the database.yml file should include

  adapter: postgresql
Sign up to request clarification or add additional context in comments.

5 Comments

Is this something that could be fixed fairly easily? I mean so that the names are corrected and error messages appropriate?
Please install the postgres adapter: gem install activerecord-postgres-adapter
what if i am just using ruby and not ror ? I can't find any datbase.yml file
@boulder_ruby - ERROR: Could not find a valid gem 'activerecord-postgres-adapter' (>= 0) in any repository.
@boulder_ruby that gem doesn't exist lmao
10

Here's the answer I got from Heroku and it worked for me (after trying different pg gems, adapters, and everything else on the 10 other posts about this)

1) add the line: gem 'pg' to your Gemfile.

2) Run the command bundle install to install the gem into your bundle.

3) Stage the Gemfile and Gemfile.lock changes: git add Gemfile Gemfile.lock

4) Commit the changes: git commit -m "Install the pg gem"

5) Redeploy to heroku: git push heroku master

Comments

9

This means you don’t have the new ‘pg’ postgresql library installed. This is easily fixed with a bit of:

sudo gem install pg

I (Dov) found other solutions on the web which described setting GEM_HOME and adding ~/.gem/ruby/vers/bin to your PATH, but they didn't work. This solution above was provided by Mark Mansour on his blog State of Flux at: http://stateofflux.com/2008/7/13/activerecord-postgresql-adapter-in-rails-2-1/

2 Comments

This one did not work for me ... still looking for a solution.
I don't recommend installing gems with sudo. Better yet, use Bundler.
6

There is one more deeply hidden condition that will also cause this error.

If you have a local environment variable DATABASE_URL=postgres://mehmehmeh set, then some gem (I suspect Heroku) causes the app to think that Postgres is required even if it's nowhere in your configs. Kill that env variable and you should be fine.

4 Comments

This was my problem. Tricky!
Really useful for me as well. I was not using pstgresql anywhere in my project but an old DATABASE_URL environment variable was there hiding and causing this.
Thank you very much. I was facing this issue till last 3 days. And finally found an answer from you @chad. Thanks again.
I was getting a bizaar error about the Active Record 'http' Adapter that was caused by this environment variable being in my .env. Glad I finally found this post!
2

Check database.yml environment db is correct. If it is postgresql, you might need to change it to refer to mysql2 or whatever db your using for your given environment.

Comments

2

You can try this

On debian(squeeze):

aptitude install libdbd-pg-ruby

Comments

1

sudo apt-get install ruby1.8-dev

then...

gem install pg

Worked for me!

1 Comment

What if we want to use 1.9.2?
0

I did a little roundup of the current state of Ruby + PostgreSQL database drivers on railsonpostgresql.com; I think sudo gem install pg is probably the one you want.

1 Comment

Thank you. I was looking for the difference between different drivers. Information not as easy to find as I thought.
0

While trying out different search results, I installed a bunch. What finally got my environment to stop complaining with this message: "Please install the postgresql adapter: gem install activerecord-postgresql-adapter" was:

  • I removed all gems relating to the adapter such as: sudo gem uninstall activerecord-jdbc-adapter; sudo gem uninstall activerecord-jdbcpostgresql-adapter; sudo gem uninstall activerecord-postgresql-adapter; sudo gem uninstall jdbc-postgres;

  • I also removed references to adapter as followed inside my Gemfile: gem 'activerecord-jdbcpostgresql-adapter'

  • Leave only pg (0.15.1) installed (to check for existence of pg, do "gem list")

Then running "rake db:create" works. So, I guess pg is the latest and works. However, it does not get used when other broken adapter gems are around.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.