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 EnterpriseDB http://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
    Alt text for the image, e.g. “The Mona Lisa”

    This could be anyone...

  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.

    I'm a real live boy!

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

Comments

6 Comments so far. Leave a comment below.
  1. Thanks for the info. Did you increase your shared memory settings in sysctl.conf like the readme file says to do? I’m wondering what if any downside there is to following that advice.

    Thanks,
    Sharon

    suggested sysctl.conf settings for a MacBook Pro with 2G of RAM:
    kern.sysv.shmmax=1610612736
    kern.sysv.shmall=393216
    kern.sysv.shmmin=1
    kern.sysv.shmmni=32
    kern.sysv.shmseg=8
    kern.maxprocperuid=512
    kern.maxproc=2048

    • I switched up my sysctl settings. The defaults that PostgreSQL sets are incredibly conservative and from the looks of them, they haven’t been revisited in at least 5 years. Changing those settings up will affect every program, so there’s an outside chance that you’ll increase shared memory space for everyone and more programs will use more memory. With 8GB of RAM, I didn’t find these settings to be problematic.

  2. Jaya prasad Rao,

    Thanks for you information. Enterprise DB should include this into faq.

    • HAHA, thanks sir. I’m glad you found it helpful. I didn’t run into the same problems with the most recent PostgreSQL installer from EnterpriseDB (I’m running PostgreSQL 9.1.0), but I ran into some other conflicts because of OS X Lion’s installation of the PostgreSQL client tools. I would guess that has been fixed, but I haven’t updated my PostgreSQL binaries to match up with the newest patch level.

  3. Shane,

    I keep getting errors like this after installing postgresql on lion:

    createuser: could not connect to database postgres: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket “/tmp/.s.PGSQL.5432″?

    Any help?

Add Your Comments

Disclaimer
Your email is never published nor shared.
Required
Required
Tips

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <ol> <ul> <li> <strong> <p>

Ready?

This site is protected with Urban Giraffe's plugin 'HTML Purified' and Edward Z. Yang's Powered by HTML Purifier. 219 items have been purified.