EDIT: I got it to work, finally. I’m not sure what changed this time around, but here are some notes I made.
This was supposed to go out last Saturday, but my blog took precedence. Oh, that, and Fable 2. Shh.
If you’ve somehow found this post in search of an answer, I have nothing but a rant for you. If the post at Robby on Rails did not work… you’re out of luck, or you’ll have to keep going and finding a solution to the mess that I ran into while trying to use PostgreSQL as my database in Rails.
I must have read that post multiple times, trying to get this to work. I hope that there’s a fourth version of that post sometime in the future… I left a comment there:
I guess I’m waiting for the 4th version of this. I think the official gem now is “ruby-pg” at http://rubyforge.org/projects/ruby-pg.
Everything is perfectly installed, except for the PostgreSQL gem. I cannot get my first rake db:migrate to work properly. It keeps telling me to install the gem “activerecord-postgresql-adapter”, which I know doesn’t exist, and it’s just a general activerecord error. I’ve tried not only the “ruby-pg” gem, but also (the now older) “postgres” as well as the “pg” (I don’t know what this one is).
Are you still using the “postgres” gem? Are things working out?
I was looking forward to rocking out in PostgreSQL land this weekend, but spending hours and hours scouring the Internet… and nothing. I might think it’s because I’m running 8.3.4, the latest version. Anyone else having my problem?
And just underneath it, someone else seemed to be having the same problems (which kinda prompted me to write this in the first place).
I don’t even want to go and document the errors I’ve gotten… Yes, I know about the ARCHFLAG. I know about the –with-pgsql-include-dir and –with-pgsql-lib-dir. I tried binaries of each gem, and even compiling from source. Blah blah blah.
Let Me Show You, The Insanity… Or The Inanity…
I really wanted this post to be titled “PostgreSQL, Ruby, and Rails: WIN.” It just turned out that I couldn’t figure it all out. I felt pretty n00b after spending the better part of three days on this (two weekends, almost). Reading up on PostgreSQL, it just seemed much more open and fully featured. Being unable to actually get it working, I said, screw it, and went with MySQL (something that I’ve played around with before).
The last time I did this, it was before Rails 2.0. I remember it being fairly painless. But now, it seems like the most recent version of PostgreSQL (8.3.4) and the most recent version of Rails (2.1.1) doesn’t seem to work together all too well. I’m guessing it’s the gems, and so it might have to do with Ruby (1.8.7) also.
The PostgreSQL gems seemed to have undergone a couple of forks. I don’t have any problem with forking… but the naming of these gems are ridiculous. It doesn’t help that PostgreSQL is like the weirdest named SQL implementation out there (let me know if there’s something named weirder). Do you shorten PostgreSQL to pg? How about just postgres? Why not call it by the full name but lowercased, postgresql? Then you have to add the ruby portion: rb or ruby. While we’re at it, let’s also call the project name different from the actual gem name itself.
At least, this is how I see this insanity. It feels like there are at least four gems that do the same thing, regardless of them being out of date or not. (pg, postgres, postgres-pr, ruby-postgres…) I must have tried most of them, to no avail. In the end, it seems like “pg” is going to be the one to follow. I think. I’ll have to come back on this later whenever I feel like experimenting with PostgreSQL again.
From the actual PostgreSQL page on the Ruby on Rails Wiki (which is totally outdated at the time of this writing):
You can install a pure Ruby postgres driver called postgres-pr using Gems:
gem install postgres-pr Note that you still have to write adapter: postgresql and not adapter: postgres-pr in your database.yml.
A faster, native driver called “postgres” is also available. It can be installed with the command:
gem install postgres
What I Think Is The Right Gem
The wiki seems to be wrong, and I believe this to be correct (from the RubyForge page):
Ruby-pg provides the module “pg”, a Ruby interface to the PostgreSQL Relational Database Management System, which supersedes the old “postgres” module. This project also maintains fixes for the old “postgres” module.
Okay… so… “Ruby-pg” is the project name. They maintain two modules, “pg” and “postgres”, even though the packages themselves are called “ruby-pg” and “ruby-postgres”. ARGH.
So That’s It
Time to start rolling. For now, I’ll go the MySQL route. There’s a larger community of people using it, as with tools and documentation and such… I’m just a little bit slightly wary of the licensing of the two.
Hey there… sorry to hear that you had some troubles. I am planning to post a new version of my post shortly. Here are some of my notes from doing a full install last week with my new MacBook Pro.
* http://gist.github.com/17502
Good luck!
If that can help, I find the solution for ruby-pg. You must specify the adapter in config/database.yml at:
adapter:postgresql
That it! No more complain by Activerecord…
Thanks
Take a look at my comments here:
http://nachbar.name/blog/2008/11/28/rails-and-p…
You're wrong Carl. I saw this “solution” as well online (I'm having the same problem), and I did originally have it set to “postgres”, which was wrong. But even after changing it to “postgresql”, I get the same type of error. Actually, with adapter set to postgres, I get this error:
“Please install the postgres adapter:
gem install activerecord-postgres-adapter(no such file to load — active_record/connection_adapters/postgres_adapter)”When it's set correct to “postgresql”, I get this error:
Please install the postgresql adapter:
gem install activerecord-postgresql-adapter(no such file to load — pg)I've tried both the ruby-pg and postgres gems, to no avail. Any help would be appreciated.
Did you try the gist that robby posted? I haven't had a chance to, but
it looks like it may work.
My solution was just to go MySQL and worry about integration with
PostgreSQL later, or maybe have that magic happen on the production
server, which has Ubuntu installed.
Thanks for the reply joshkim.
Well, all that's being done there in the gist to do with this is “sudo gem install postgres”, which is sorta obvious. I don't think the problem is with the gem, though I've tried uninstalling and installing a few times, and tried the other ruby-pg gem too. Robby doesn't have the same error I do. The error shows up when doing a rake command to create the database, and occurs for others when trying a rake db migration command.
I think this error only shows up with the latest rails, because I've been using postgresql on my laptop with rails 2.1.1 for a while. But it messes up on my server, which has rails 2.2.2 installed. The problem doesn't seem to be with the gem, but with activerecord itself. I don't know nearly enough about rails to begin trying to solve it though.
I guess I may switch to mysql for now myself, just to get things working, but that isn't really a solution to me.
Yeah, same here. I started poking around in rails to see how I could
fix it, but I gave up after gobs and gobs of time spent on it. I also
remember it working in 2.1, because I was working on another rails
project back then… but something must have changed with 2.2.
i got this setup working
postgres 8.3.5
nb 6.5 ruby
postgres-pr 0.5.0
there are instructions on a blog on the dzone site, by some indian guy, it definitely works
you need to create the db before working with it from nb, once its created, migrations do work, but for some reason the inital create:db doesnt work.
Mustafá, I woud like to find the 'blog on the dzone site, by some indian guy' Could you tel us the url
Yeah Mustafa.. the url would've been a cool addition to your comment..
you folks want to be spoon-fed, hmmm i dunno, here you go
http://blogs.sun.com/jkshah/entry/postgresql_an…
argh thats what i get for rushing my reply
heres the correct url
http://netbeans.dzone.com/news/rails-and-postgr…
I’ve done a couple of rails installs now on laptops and found myself in the exact same situation as you when installing on a new box — real headscratcher. My problem was this: I’d installed rubygems via macports but neglected to install a fresh copy of rake via rubygems, which meant that when doing a rake db:migrate, it would find OS X’s native rubygems. I only figured this out because script/server (which relies on the ruby binary) was working where rake was not.
A ‘gem install rake’ (and a new terminal window to clear the bash path cache — try saying that out loud) fixed me right up.
If this command doesn’t return three binaries in the same directory for you, you might be in the same boat:
$ which ruby rake gem
-john
I had the problem with:
Building native extensions. This could take a while… ERROR: Error installing pg: ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb install pg extconf.rb:1:in `require’: no such file to load — mkmf (LoadError) from extconf.rb:1
This solved by running:
sudo aptitude install ruby rubygems ruby1.8-dev
I’ve just realised the ruby-pg actually is the gem called postgres – at least they both have exactly the same version at the time of writing – 0.7.9.2008.01.28. We’ve been using postgres for some time with great success.
For what it's worth, I fixed this problem on my Fedora 9 system with:
sudo yum install ruby-devel sudy gem install pg
joshkim, where did you post the solution? I’ve been stuck all day trying to get through this. Thanks!
Oh, it’s the first link I added as an edit. http://joshkim.org/2009/02/15/postgresql-ruby-and-rails-win/
Don’t know if it’s what you’re looking for…
Thanks for the post! This helped me using Taps and heroku to pull data to a local postgres db. Taps failed with a mysterious errror: Failed to connect to database: Sequel::AdapterNotFound -> LoadError: no such file to load — pg
Installing ruby-pg solved it.
lol @ Segedunum
I got the error: Please install the postgresql adapter:
gem install activerecord-postgresql-adapter(no such file to load — pg)and I read on this blog so I did: sudo gem install pg
and Yay! it’s working
Thank you,
Yeah, this was a specific issue with Mac OS X. It eventually got
resolved. I posted in another post with the solution.