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…
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!
For notes on making the database accessible over the network, please refer to one of my posts on PostgreSQL on Ubuntu.