installing postgresql 8.2 on Leopard with macports

postgresql! one of my favorite high performance open source db, of course i have it running on my mac. compiling postgresql with macports isn’t that hard, follow the step below will guide you through the installation;

first of all, make sure your macports is updated by running the command;

sudo port -v selfupdate
sudo port -v sync # some user prefer to run port sync, port selfupdate does the same thing.

installing postgresql, start it and create super user

sudo port -v install postgresql82-server # compile and install postgresql database from macports.

by default, macports will create postgresql database directory and initialize the db.

[ 149]$ ls -al /opt/local/var/db/postgresql82/
total 0
drwxr-xr-x 3 root admin 102B Nov 13 21:27 .
drwxr-xr-x 3 root admin 102B Nov 13 21:27 ..
drwx—— 16 postgres postgres 544B Mar 10 16:35 defaultdb

if the db directory is not created, follow the step below;

sudo mkdir -p /opt/local/var/db/postgresql82/defaultdb # make database directory
sudo chown postgres:postgres /opt/local/var/db/postgresql82/defaultdb # assign postgre user and group
sudo su postgres -c ‘/opt/local/lib/postgresql82/bin/initdb -D /opt/local/var/db/postgresql82/defaultdb’ # initialize default database

the default installation doesn’t include postgresql binary file into /opt/local/bin, add postgresql executable files into your shell environment

takizo@redarrows(~)
PATH=${PATH}:/opt/local/lib/postgresql82/bin

now, we will launch postgresql database and create super user and database

takizo@redarrows(~)

sudo /opt/local/etc/LaunchDaemons/org.macports.postgresql82-server/postgresql82-server.wrapper start
server starting # start postgresql database

sudo su – # switch to root user

sudo posrgres – # switch to postgres user

/opt/local/lib/postgresql82/bin/createuser -s -d -r -P

exit # quit as postgres user

exit # quit as root user

createdb -O takizo takizo # create database with takizo as privilege user

You are done, now you can logon to postgresql database with your username (mine is takizo)

psql82 -U takizo takizo

Since you have created super user, next time you can create new user with createuser command,

createuser -S -D -R -P -U takizo edward # create user edward with privilege account takizo
Enter password for new role: # password is hidden :p
Enter it again: # confirmed password is hidden too 🙂
CREATE ROLE # new user has been created

Happy playing with postgresql database!