OSX Lion ships with the PostgreSQL client tools, as well as a
_postgres daemon user. I wanted to add a full PostgreSQL server in a way that was compatible with these tools and without creating an extra user account.
This recipe uses HomeBrew to do the heavy lifting. If you haven't already got it, head over to http://mxcl.github.com/homebrew and install it.
First, make sure brew is up to date:
$ brew update
Start the install process:
$ brew install postgresql
This will take a few minutes to download and eventually end with something like this:
==> Summary /usr/local/Cellar/postgresql/9.0.4: 2577 files, 34M, built in 77 seconds
Next, initialize the database storage with this command:
$ initdb /usr/local/var/postgres
psql command (and many apps) expect to connect to a local PostgreSQL
database using a unix domain socket in
/var/pgsql_socket. This is currently owned by
_postgres user so we need to fix that:
$ sudo chown $USER /var/pgsql_socket/ Password:
Now create a
launchctl configuration to start the database automatically. First, copy the default config file:
$ mkdir -p ~/Library/LaunchAgents $ cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/
~/Library/LaunchAgents/org.postgresql.postgres.plist in a text editor and look for this line:
Paste in the following lines immediately below it:
<string>-c</string> <string>unix_socket_directory=/var/pgsql_socket</string> <string>-c</string> <string>unix_socket_group=_postgres</string> <string>-c</string> <string>unix_socket_permissions=0770</string>
Start the database server like this:
$ launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
_postgres account as a database user (with no password):
$ createuser -a -d _postgres
Finally, verify that it's all working by connecting:
$ psql template1 -U _postgres psql (9.0.4) Type "help" for help. template1=#
You should also be able to connect with a TCP/IP connection to localhost, port 5432.
© Copyright 2009-2012 Peer Assembly | All Rights Reserved.