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 databasesudo 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!
in the installing time what i write in the password box
[…] I wrote a post on “installing postgresql 8.2 on Leopard with macports“, seem like quite a no. of people also interested to know how to MySQL5 as server on Mac […]
Thanks for this posting, it saved my day (ehm… night). Especially the selfupdate of MacPorts at the beginning, I would have given up because it was some months old and it did not find any PgSQL sources anymore.
I have a question on the first “createuser” call: is there something missing, the user name? Because at that point the postgres user should already exist…
[…]
> /opt/local/lib/postgresql82/bin/createuser -s -d -r -P […here???…]
> exit # quit as postgres user
[…]
@Victor
The postgres user does already exist in the OS at that point. The createuser command is for creating users (technically roles) within postgresql itself. After running the command it prompts for the name of the role if you do not specify it on the command line.
Here is a URL for the full documentation of the command:
http://www.postgresql.org/docs/8.3/static/app-createuser.html
@Em
Thanks for your reply.
I think I understand now: the user (or role how it is called in PostgreSQL) named “takizo”, which is used two lines later, was created interactively during this step. That was the missing link for me.
slight misspelling here, should be postgres, not portgres:
sudo port -v install portgresql82-server