Mac Postgres Installation the Easy Way

If you use PostgreSQL, and why wouldn’t you, then you know how nice it would be to have a local install of Postgres to run all your local_dev Django apps on. Not only can you have a real database that you can enter real data into for export to a production server later, but it also makes it uber easy to export a live database and work with a full data set locally, saving you tons of time entering crap data just so you can see what is going on, and more importantly catching more bugs in the process.

So lets get rolling. To install Postgres on your Mac simply follow these steps:

  1. Postgres is now available in a super easy to install package. Just go download Postgres for Mac and run the installer. Make sure and set a superuser password that you will remember. You can use StackBuilder to also install phpPgAdmin which makes database administration super easy.

Installing Psycopg2 using macports works but it sucks to have to do that. I’m leaving the instructions but its much easier to just install Psycopg2 the easy 1 step way below.

2. The new way - Note that your Postgres install directory could be different, mine is /Library/PostgreSQL/8.4 and you need that to be correct for this command to work. Simply…

PATH=$PATH:/Library/PostgreSQL/8.4/bin/ sudo easy_install psycopg2

You are done!

  1. The OLD way - If you don’t already have macports, download and install darwin ports: http://darwinports.com/

  2. Don’t forget to run sudo port -d selfupdate in a terminal window when you are done.

  3. Install Psycopg2 - Super easy at this point, just open a terminal window and…

    sudo port install py25-psycopg2
    
  4. Now, we just need to link the psycopg2 directory because it gets put in a weird location by Macports. Go to your main Python path directory (if you don’t know where that is just run this in terminal)

    python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
    

    Once at that directory do something like this. Note that you may need to change these folder names depending on the version of Postgres that you install.

    ln -s /opt/local/var/macports/software/py25-psycopg2/2.0.13_0+postgresql84/opt/local/lib/python2.5/site-packages/psycopg2
    

Thats it! You’ve now installed Postgres on your Mac. You can either export and import your external database locally via command line or you can simply export it via phpPgAdmin and import it the same way. Make sure to change the user who owns the database locally to the correct one.

Cheers!


Comments