Postgres on Mac

VIA:    http://www.peerassembly.com/2011/08/09/installing-postgresql-on-lion/
            http://digitheadslabnotebook.blogspot.in/2011/10/postgresql-cheat-sheet.html
Install
> brew install postgresql

Initialize database
initdb /usr/local/var/postgres


Changing ownership
sudo chown $USER /var/pgsql_socket/

Add to startup items
mkdir -p ~/Library/LaunchAgents
> cp /usr/local/Cellar/postgresql/9.0.4/org.postgresql.postgres.plist ~/Library/LaunchAgents/

Now, edit ~/Library/LaunchAgents/org.postgresql.postgres.plist in a text editor and look for this line:
/usr/local/var/postgres/server.log

Paste in the following lines immediately below it:
-c
unix_socket_directory=/var/pgsql_socket
-c
unix_socket_group=_postgres
-c
unix_socket_permissions=0770

Start the DB
> launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist

Add the _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

Grant access privileges

> create database dbname;
> create user joe_mamma with password 'password';
> grant all privileges on database dbname to joe_mamma;
> grant all privileges on all tables in schema public to joe_mamma;
> grant all privileges on all sequences in schema public to joe_mamma;



Comments