Installing, Configuring and Troubleshooting PostgreSQL 9.0 in Rails 3 on OS X

The following may apply to other versions of PostgreSQL as well but I’m using version 9.0.

I initially tried to install PostgreSQL via MacPorts but after running into issues I describe below, I ended up installing it via the Mac OS X package. If you want to skip issues I ran into with my macports attempt to install PostgreSQL, go to Install PostgreSQL via Mac OS X package

navid@~: sudo port install postgresql90 postgresql90-server
Error: Port postgresql90 not found

From the Macports Guide, I then learned that I have to sync the local ports tree periodically and I had never done that before. You should do the following:

navid@~: sudo port selfupdate
--->  Updating the ports tree
--->  Updating MacPorts base sources using rsync
MacPorts base version 1.8.0 installed,
MacPorts base version 1.9.1 downloaded.
--->  MacPorts base is outdated, installing new version 1.9.1
Installing new MacPorts release in /opt/local as root:admin; permissions 0755; Tcl-Package in /Library/Tcl

The ports tree has been updated. To upgrade your installed ports, you should run
  port upgrade outdated

Once my local ports tree was updated, I was then able to install PostgreSQL 9.0 by doing the following:

* Be ready for this next step… It will take a while to install.

sudo port install postgresql90 postgresql90-server

Once I did the above, I had ran into some issues but unfortunately didn’t document those errors. :(
I just worked around my issues by doing the following instead:

Install PostgreSQL via Mac OS X package

Go to PostgreSQL Mac OS X package
After reading its README before installing, I decided to go with the default kernel settings and not worry about configuring the /etc/sysctl.conf file myself, for now. These settings matter more for a Production environment and since I’m using Heroku, I’m not going to worry about changing them until I run into issues on my development machine.

I double-clicked on the package file to install PostgreSQL and it told me that it configured the /etc/sysctl.conf for me with the following:


Test your Database Connection from your Rails app

Assuming you’ve already created you’ve used pgAdmin III from your Applications folder to create a new database, you should configure your rails app.

If your connection is successful, you should see no errors when doing the following:

cd your_rails_directory
rake db:schema:dump

Create new Rails Project and Configure it to use PostgreSQL

I created a new rails project by doing the following:

rails new project_name -d postgresql

My database.yml file looks like the following, for my development environment. It will be different for yours. Replace project_name_development, username and password with yours:

  adapter: postgresql
  encoding: unicode
  database: project_name_development
  pool: 5
  username: project_name

At this point, add the following to your PATH, assuming you installed PostgreSQL at the default location on your Mac:


Also, set your ARCHFLAGS environment variable, if it’s not already set:

ARCHFLAGS=-arch i386

bundle install
VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
Facebook Twitter Email

Leave a Reply