0

I'm new to Ruby on Rails. I installed Rails 4 on my Windows 8 system, and the DevKit, and installed the pg (PostgreSQL) gem.

> gem install pg
...
Successfully installed pg-0.16.0-x64-mingw32

I created a new rails application:

> rails new blog -d postgresql

But when I start rails server

> cd blog
> rails server

and navigate to the localhost:3000 in my browser, I see this error:

Gem::LoadError Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile.

My Gemfile includes these lines:

# Use postgresql as the database for Active Record
gem 'pg'

Additionally, if I do

bundle install

pg is not listed in the output.

If I do

require 'pg'

in the Ruby console I get

=> true

This question is very similar to

Rails 4 postgres bug - cannot create database because the pg gem "is missing", but it is not

but in that case the questioner realized he was using an older version of the pg gem. I have the version that was installed with gem install pg, which I assume is the most recent one.

Can anyone provide some troubleshooting guidance?

Update:

From the comment by @vinodadhikary I tried bundle update pg

which returned

Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..
Resolving dependencies...
Using rake (10.1.0)
...
Your bundle is updated!

without mentioning pg.

I then tried bundle show pg, which returned

Could not find gem 'pg'.
Did you mean pg?

I tried running the server again, and received the same error.

Update 2

I have my config\database.yml file configured per my existing postgres database, like

development:
  adapter: postgresql
  encoding: unicode
  database: rails_dev
  pool: 5
  username: postgres
  password: [password]
  host: localhost
  port: 5433

and likewise for test and production. Thanks Artiwarah Damrongchai for suggesting that.

2
  • Troubleshooting: try bundle update pg and check bundle show pg Commented Jul 26, 2013 at 1:04
  • Thanks vinodadhikary, I tried that and edited the question with an update of the results. Commented Jul 26, 2013 at 5:10

2 Answers 2

3

Thanks to some help from Andy Henson on #RubyOnRails IRC I was able to solve this issue, or at least work around it.

It seems like the issue may be with the way bundler identifies 32 and 64bit versions of the minGW build environment provided by DevKit. There's an outstanding bug here that looks relevant:

https://github.com/bundler/bundler/issues/2356

But I was able to work around it by switching from using 64bit everything to using 32bit everything. Here are my steps:

I uninstalled 64bit Ruby. Then from http://rubyinstaller.org/downloads/ I installed

  • rubyinstaller-2.0.0-p247.exe
  • DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe

Then I installed a 32bit version of postgres to C:\PostgreSQL\9.2

Then I installed the pg gem using

subst X: "C:\PostgreSQL\9.2"
gem install pg -- --with-pg-dir=X:
subst X: /D

(The subst command was overkill in this case, because there were no spaces in the postgres path, but it's a good trick to know for other situations.)

Then in my application host directory I ran rails new blog -d postgresql, and edited my conf\database.yml file per my postgres settings. This seems to have solved it.

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

Comments

0

Maybe you need to config your database.yml file like this:


development: &default
  adapter: postgresql
  host: localhost
  encoding: unicode
  database: your_database
  username: your_username
  password: your_password
  pool: 5
  timeout: 5000

1 Comment

Thanks Artiwarah, I did indeed configure my database.yml file per my existing postgres database. I have updated my question to reflect that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.