I ran into a few issues while installing the "pg" gem that is required for communication with the Postgres database.  The error that I was seeing was:

Can‘t find the ‘libpq-fe.h header
*** extconf.rb failed ***

I didn't understanf because I had Postgres installed correctly in the /Library/PostgreSQL directory.  After doing some research I figured it out.  The build architectures between Ruby and Postgres were not matching.

I ran the following to figure out what the architectures were.

For Ruby:

file $(which ruby)

/Users/ammarmayk/.rvm/rubies/ruby-1.8.7-p330/bin/ruby: Mach-O 64-bit executable x86_64

For my Postgres 8.4:

file $(which psql)

./psql: Mach-O universal binary with 2 architectures
./psql (for architecture ppc):    Mach-O executable ppc
./psql (for architecture i386):    Mach-O executable i386

As you can see Postgres was not build for the x86_64 architecture and that is all I had for my Ruby.  So I decided to upgrade the Postgres to the newest version, 9.0.

I downloaded the DMG installer from the Postgres site and installed it, I made sure to replace Postgres 8.4 with the new 9.0 in my .profile file.

I added this to the path /Library/PostgreSQL/9.0/bin.

Then after this I ran the file command again, this time Postgres showed that it had been built for the x86_64 architecture.

ammar-yousufs-macbook-pro:~ ammarmayk$ file $(which psql)
/Library/PostgreSQL/9.0/bin/psql: Mach-O universal binary with 3 architectures
/Library/PostgreSQL/9.0/bin/psql (for architecture ppc7400):    Mach-O executable ppc
/Library/PostgreSQL/9.0/bin/psql (for architecture i386):    Mach-O executable i386
/Library/PostgreSQL/9.0/bin/psql (for architecture x86_64):    Mach-O 64-bit executable x86_64

Now when I did a "gem install pg" it all went through without any problems.

Hope that helps anyone having Postgres woes.