Install PostgreSQL on Mac OS X Leopard

This type of guide is all over the internet, but I’m too lazy to search for one every time I want to do this. ;) So here’s a brief overview of how I got PostgreSQL set-up nicely on Mac OS 10.5…

Setting Up Our Environment

Using a text editor of your choice, add the following lines to the bottom of the /etc/profile file (you’ll need to be an administrator to do this):

# MacPorts
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
 
# PostgreSQL
export PATH=/opt/local/lib/postgresql83/bin:$PATH

Now before we move on, make sure that you have MacPorts installed.

Installing PostgreSQL with MacPorts

I like MacPorts - it makes installing general Unix packages and keeping them up-to-date a snap. As such, we’ll use it to do the heavy lifting for installing PostgreSQL. Open up a terminal and hit up the following command:

sudo port install postgresql83 postgresql83-server

Sit back and wait a while… That’s the basic install done.

Now to configure it, do the following:

sudo mkdir -p /opt/local/var/db/postgresql83/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql83/defaultdb
sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/defaultdb'

This installs a default database instance for us to be getting on with. Next, run this command to get PostgreSQL to start on system boot:

sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql83-server.plist

Reboot your Mac.

Creating a User Account and Database

Once your Mac is back up, we finally need to create an account for us to use (substitute ‘daz’ for your username)…

createuser --superuser daz -U postgres

Now a database to play with…

createdb test_db

Admin Your Database with pgAdmin 3

Download pgAdmin, then run the following commands to set up some functions that allows pgAdmin to collect statistics about your databases:

cd /opt/local/share/postgresql83/contrib/
sudo su postgres -c psql < adminpack.sql

That’s it - job done!1


  1. For notes on making the database accessible over the network, please refer to one of my posts on PostgreSQL on Ubuntu

Spread the Word
  • Twitter
  • del.icio.us
  • Digg
  • Facebook
  • Google Bookmarks
  • Reddit
  • NewsVine
  • Slashdot
  • connotea
  • HackerNews
  • Print
  • email

About Daz

This is the blog of Darren Oakley
This entry was posted in mac, postgresql and tagged , , , . Bookmark the permalink.

2 Responses to Install PostgreSQL on Mac OS X Leopard

  1. Thanks, the tip on installing the adminpack was very helpful especially.

  2. mac leopard says:

    Very Good information,I have Digged this site for future and will keep a eye on your other postings. Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">