Chronicling My Ruby on Rails Journey

March 12, 2010

Getting PostgreSQL to install on Windows

Filed under: Database,rails,ruby rails — Bob Ngu @ 11:19 am
Tags: ,

In the effort to migrate my existing Rails app from Slicehost to Heroku, I encountered some MySQL – PostgreSQL compatibility issues, I’ll write a separate post on Heroku gotchas later. In order to debug those issues, I need to install PostgreSQL on my local Windows development machine. Did you think it’ll be trivial? Of course not, nothing open source is ever trivial on Windows…. nothing, trust me on that.

First thing first, install PostgreSQL (V8.4.2-1 as of this article’s date).

And silly me, first thing I tried was gem install postgres, not even close. A little research led me to this article to try gem install ruby-postgres. That seemed to work.

Next I tried to run rake db:create, if memory serves me correctly, I ran into this error

Can’t activate rubyforge (= 0.4.4, runtime), already activated rubyforge-1.0.0 (Gem::Exception)

To fix it, I followed the advice in this article.

From here onwards, I kept trying rake db:migrate and got several other errors for libpq.dll, libeay32.dll, ssleay32.dll, and a whole slew of other missing DLLs. According to this article, it said to

You need to go back to the postgres installer file and
copy a couple of libraries to the ruby “bin” file (for example in
c:\ruby\bin\)

* comerr32.dll
* krb5_32.dll
* libeay32.dll
* libiconv-2.dll
* libintl-2.dll
* libpq.dll
* ssleay32.dll

Don’t overwrite any files if they already exist in the ruby directory !

I tried the advice without much success because I kept getting DLL errors like missing DLLs and like

ruby.exe – Ordinal Not Found
The ordinal 284 could not be located in the dynamic link library SSLEAY32.dll.
and
The ordinal 2821 could not be located in the dynamic link library LIBEAY32.dll.

Bottom line, don’t try the advice from the above article, it is outdated and there are new DLLs added to PostgreSQL since then, restore ruby\bin to what it was if you did try. Then I came across this article saying to add C:\Program Files\PostgreSQL\8.4\bin to your Windows path which as it turns out, installing PostgreSQL didn’t do, why I have no freaking idea.

Anyway, after adding the path, I’m still getting the ordinal could not be located in the DLL errors for LIBEAY32.DLL and SSLEAY32.DLL. It turns out that those 2 DLLs support OpenSSL and my machine is littered with multiple copies of it from cygwin, Google, SVN, Ruby, Postgres, VMware, etc. It’s a freaking mess. I took a cue from from this posting and copied those 2 files from C:\Program Files\PostgreSQL\8.4\bin to C:\ruby\bin. First, rename those 2 files in C:\ruby\bin to something else just in case you need them for some other reason before you copied them from PostgreSQL.

The final thing you need to do is to change your database.yml file to something like this

development:
adapter: postgresql
database: DATABASENAME
username: YOURUSERNAME
password: YOURPASSWORD
host: localhost
encoding: UTF8

And now run rake db:create and rake db:migrate and you should be good to go. I think I got a headache writing this post.

Advertisement

5 Comments »

  1. Another gotcha is that text searches in PostgreSQL are case sensitive. So in Postgres ‘Apple’ is not equal to ‘apple’. That can cause some issues depending on what you’re doing in your app. It can also mess with sorting (order by)

    Comment by Michael — March 16, 2010 @ 7:06 am | Reply

  2. I can’t express how much I love you right now. Thank you for taking the time to write this.

    Comment by Zach — August 19, 2010 @ 11:56 am | Reply

  3. Rails developers on Windows unite. Thanks so much.

    Comment by Sam — March 11, 2011 @ 2:39 pm | Reply

  4. Hello, Really thank you for this nice article.

    i’m getting following errors after I carryout the all the steps.

    received invalid response to SSL negotiation: -
    

    Please u please advice me on this issues.

    Comment by makewebapp — December 26, 2011 @ 10:02 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.