This is the steps needed to install a working copy of postgresql in Mac OSX Mountain Lion 10.8.3 using Homebrew. It is assumed that you have Homebrew already installed.
Update your homebrew.
Fix any errors shown.
brew install postgresql
Create a database.
initdb /usr/local/var/postgres -E utf8
Chances are there's an error if you create a database. If not, skip to steps on automatically load postgresql on login.
FATAL: could not create shared memory segment: Cannot allocate memory
Thanks to Dave Baker's article, there are 2 options to fix that, either you reduce postgresql shared memory usage, or increase the system settings. Well, I choose the later option as He suggested.
sudo sysctl -w kern.sysv.shmall=65536 sudo sysctl -w kern.sysv.shmmax=16777216
Unfortunately the system setting will be reset after restart with only those command above. To retain the memory settings, execute the following command and recreate the database.
sudo tee -a /etc/sysctl.conf <<EOF kern.sysv.shmall=65536 kern.sysv.shmmax=16777216 EOF initdb /usr/local/var/postgres -E utf8
Automatically load on login.
ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
Test if your database is running.
psql -d postgres