Installing PostgreSQL on Mac OS X

This is a pretty simple process, but one that I thought I would document because I ran into a few gotchas along the way. I originally installed OS X using the one click installer from EnterpriseDB. Unfortunately, the installer hung while attempting to finish the installation process and they only thing to do was to roll back the install. I attempted to build from macports, but that proved to be a huge pain in my ass and reminded me a little bit too much of using Linux, so I scrapped that idea as well. I started browsing the EnterpriseDB installation notes and came across an unattended install. Since my installation failed trying to launch the final interactive stage of the installation, I said to myself “Self, I bet we should try this.”

  1. Download PostgreSQL from EnterpriseDBhttp://www.enterprisedb.com/products/pgdownload.do#osx

  2. Mount the OS X disk image file

  3. In the Terminal, change to the directory where the image file was mounted: cd /Volumes/PostgreSQL\ 8.4.2-1/

  4. Start the unattended installation sudo ./postgresql-8.4.2-1-osx.app/Contents/MacOS/installbuilder.sh --mode unattended

  5. Once the installation has finished, add the following line to your .profile: source /Library/PostgreSQL/8.4/pg_env.sh If you’ve never created your .profile you can do the following in a terminal window:

    1. touch ~/.profile This will create the file if it doesn’t exist and will only change the last modification date if it does.
    2. open /Applications/TextEdit.app .profile This opens your .profile in the TextEdit application
  6. Save and close your .profile

  7. Create a new database user. createuser [YOUR NAME HERE] --pwprompt --username=postgres

    [caption id=“attachment_1346” align=“alignnone” width=“515”] This could be anyone…[/caption]

  8. When you’re prompted for the “Password:”, use “postgres”. This is the default password for the postgres superuser. Because you’ve just created another superuser, you’ll never have to touch this account again, but you should probably look up some fantastic documentation and learn how to change the password.

    [caption id=“attachment_1345” align=“alignnone” width=“506”] I’m a real live boy![/caption]

There you have it: how to set up and install PostgreSQL on OS X. If you want to continue forward and install a Ruby library to interact with PostgreSQL, just type sudo gem install postgres-pr to install the pure Ruby version PostgreSQL driver. If you want to install one of the C-based drivers, you’ll need to mess around with macports. Note: EnterpriseDB make and distribute a binary version of PostgreSQL for a variety of platforms. In addition, they provide paid support and also offer a variety of enterprise features. They have in no way paid me for this post.


Related Posts: PostgreSQL Tutorial – Creating Your First Database PostgreSQL Tutorial – Creating the Pagila Schema PostgreSQL Tutorial – Referring to Other Tables PostgreSQL Tutorial – Inserting Data