Postgresql on Windows 7 and Rails Installation Nightmares

So recently, I decided to give Heroku a shot along with Ruby on Rails for my backend development. Heroku though uses Postgres as their default database whereas Rails uses sqlite3. To get everything synch’d up, I finally decided to switch my local environment to use Postgres. Instead, this thing turned out to be a pretty big nightmare and I want to share what some of the stumbling blocks I encountered in getting everything to work together.

Assuming that you have a basic Heroku environment all ready to go and possibly even pushed to the Heroku servers, the main thing you’ll want to do is install Postgres. The current version of Postgres on Heroku looks to be 9.3.5 according to the command:

heroku pg:info

So you probably should try to stick to that version or lower even. I ended up going down to 9.0 just because of various issues I had along the way. One thing that you should do is get the x86 version and NOT THE 64-bit version. The pg driver for rails is not compatible on Windows for whatever reason and you’ll repeatedly hit errors of not being able to find the correct libpq libraries.

Once you get your packages and have a Postgres installed on your system, you’ll want to edit your system level variables so that your path includes your installation to the bin directory. To do this just go:

  • Open Windows Explorer
  • Right click on Computer
  • Click on “Advanced system settings” on the left pane
  • Click on the “Environment Variables” under the “Advanced” tab for System Properties
  • Then edit the PATH variable under “System variables”. Add the path to your local Postgres installation (e.g. “c:\Program Files (x86)\PostgreSQL\9.0\bin”)
  • Click Ok

If you’re already in a command prompt, you’ll probably want to restart it in Admin mode so that you can see the updated System variables.

Now, in your rails installation, you will want to run the commands:

gem install pg --pre
bundle install

The issue here is that there seems to be some compatibility issues with the current 0.18 driver. Using the pre-release version seems to solve it. One way to test whether things are busted if just trying to turn your server on by issuing out a command like:

rails s

If things work out, you shouldn’t get any issues (Cannot find/load pg_ext is the common error here). You can even try running a migration to make sure you can connect to your database from rails.

Unfortunately, for myself, I ended up spending almost half my day trying to get this setup correct. I did things like downgrading from 9.4 to 9.3, moving directories around, experimenting with the pg driver in rails, spending time trying to figure out how to run the command prompt as Admin for a specific directory that had no content if the prompt was run elsewhere, etc. It was a real pain overall with no unified documentation to walk you through. Also, I’m a bit sad about not being able to take advantage of the current Postgres version just because I just want to make sure everything works with my current setup. Of course, I can upgrade it in the future but having an older version is a safety net in terms of proven support.

At any rate, despite how simple the end solutions are, much of what happened for me was just running through hundreds of useless questions and older articles that did not seem relevant anymore. So hopefully, by posting my experience in this situation, people can avoid this problem for themselves in the future.

Of course, the other issue you might ask is, “Why the hell are you developing on Windows in the first place?” Unfortunately, my Windows machine is my most powerful box for development and my Macbook simply lacks power to handle a lot of what I need to get done at this point. Hopefully, if I can get some money, I’ll be able to get a more powerful Macbook and avoid this unnecessary suffering. But in the meantime I have to make due.

 

 

(Visited 294 times, 1 visits today)

Comments

comments


Posted

in

,

by

Comments

One response to “Postgresql on Windows 7 and Rails Installation Nightmares”

  1. Keith Watanabe (@conark) Avatar

    Postgresql on Windows 7 and Rails Installation Nightmares http://t.co/vGBM9apzep

Leave a Reply