Search code examples
ruby-on-railspg

RAILS: gem pg not loaded after upgrading ruby from 2.2 to 2.3.3


I just upgraded ruby from 2.2.4 to 2.3.3 for my Rails 4.2.0 app with postgres 9.5. When starting rails s, the pg adapter was not loaded:

C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/activerecord-4.2.0/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'postgresql' for data
base adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)

I did gem install pg to install the pg adapter and gem list shows that pg 1.1.3 adapter was installed. However the pg adapter was still not found when starting Rails server.

Is the adapter version too new for Rails 4.2.0?

gemfile:

source 'http://rubygems.org'

gem 'rails', '4.2.0'

gem 'pg'

gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
.........

gem list output:

*** LOCAL GEMS ***

actionmailer (4.2.0)
actionpack (4.2.0)
actionview (4.2.0)
activejob (4.2.0)
activemodel (4.2.0)
activerecord (4.2.0)
activesupport (4.2.0)
addressable (2.5.2)
arel (6.0.4)
bcrypt (3.1.12 x64-mingw32)
bigdecimal (1.2.8)
binding_of_caller (0.8.0)
builder (3.2.3)
bundler (1.17.1)
byebug (10.0.2)
capybara (3.12.0)
coffee-rails (4.1.1)
coffee-script (2.4.1)
coffee-script-source (1.8.0)
concurrent-ruby (1.1.3)
crass (1.0.4)
database_cleaner (1.7.0)
debug_inspector (0.0.3)
did_you_mean (1.0.0)
diff-lcs (1.3)
erubis (2.7.0)
execjs (2.7.0)
factory_girl (4.9.0)
factory_girl_rails (4.9.0)
ffi (1.9.25 x64-mingw32)
globalid (0.4.1)
gon (6.2.1)
hike (1.2.3)
i18n (0.9.5)
io-console (0.4.5)
jquery-rails (4.3.3)
jquery-ui-rails (6.0.1)
json (2.1.0, 1.8.6, 1.8.3)
launchy (2.4.3)
loofah (2.2.3)
mail (2.7.1)
mini_mime (1.0.1)
mini_portile2 (2.3.0)
minitest (5.11.3, 5.8.5)
multi_json (1.13.1)
net-telnet (0.1.1)
nokogiri (1.8.5 x64-mingw32)
pg (1.1.3 x64-mingw32)
power_assert (0.2.6)
protected_attributes (1.1.4)
psych (2.1.0)
public_suffix (3.0.3)
rack (1.6.11)
rack-test (0.6.3)
rails (4.2.0)
rails-deprecated_sanitizer (1.0.3)
rails-dom-testing (1.0.9)
rails-html-sanitizer (1.0.4)
railties (4.2.0)
rake (12.3.1, 10.4.2)
rb-fsevent (0.10.3)
rb-inotify (0.9.10)
rdoc (4.3.0, 4.2.1)
regexp_parser (1.3.0)
request_store (1.4.1)
responders (2.4.0)
rspec-core (3.8.0)
rspec-expectations (3.8.2)
rspec-mocks (3.8.0)
rspec-rails (3.8.1)
rspec-support (3.8.0)
sass (3.7.2)
sass-listen (4.0.0)
sass-rails (5.0.7)
sdoc (0.4.2)
simple_form (3.1.1)
sprockets (2.12.3)
sprockets-rails (2.3.3)
sqlite3 (1.3.13 x64-mingw32)
test-unit (3.1.5)
thor (0.20.3)
thread_safe (0.3.6)
tilt (1.4.1)
tzinfo (1.2.5)
tzinfo-data (1.2018.7)
uglifier (2.7.2)
web-console (2.3.0)
will_paginate (3.1.6)
workflow (1.2.0)
xpath (3.2.0)
yajl-ruby (1.4.1)

Solution

  • Looks like your rails and pg gem versions are incompatible: https://github.com/rails/rails/issues/31673

    I see three options:

    • Downgrade pg gem to an older version (probably 0.xx)
    • Upgrade to Rails 5.1.5 or newer
    • Try the hacky workaround described in the github issue (wouldn't recommend)