Notes on Setting Up PostgreSQL - JerJohn15/cambridge_energy_app GitHub Wiki
Notes on Setting Up Postgres
Many Mac users have struggled setting up PostgreSQL with Homebrew. Since I often find myself repeating the same troubleshooting steps I'm providing them here. This assumes you have already installed Homebrew and RVM. If you are looking for an initial setup of your development environment go to http://installrails.com.
Step 1
brew install postgres
You will receive the following message which has some good advice, but might not be the best way to proceed:
If builds of PostgreSQL 9 are failing and you have version 8.x installed, you may need to remove the previous version first. See: https://github.com/Homebrew/homebrew/issues/2510
To migrate existing data from a previous major version (pre-9.0) of PostgreSQL, see: http://www.postgresql.org/docs/9.5/static/upgrading.html
To migrate existing data from a previous minor version (9.0-9.4) of PosgresSQL, see: http://www.postgresql.org/docs/9.5/static/pgupgrade.html
You will need your previous PostgreSQL installation from brew to perform
pg_upgrade. Do not runbrew cleanup postgresqluntil you have performed the migration.To have launchd start postgresql at login: ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents Then to load postgresql now: launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Or, if you don't want/need launchctl, you can just run: postgres -D /usr/local/var/postgres
Step 2
Instead of following the instructions above I recommend following Thoughtbot's Instructions for installing brew services. Then you should be able to run brew services start postgresql to start Postgres.
Step 3
Test connecting to your database by typing psql in a console. Sometimes it fails due to an issue referenced here. The quick and easy fix is to stop running postgres, run rm -rf /usr/local/var/postgres && initdb /usr/local/var/postgres -E utf8 and then restart postgres, but you may want to read this comment for more detail or if you had a previous Postgres version installed.