Skip to content

Instantly share code, notes, and snippets.

@antonior92
Last active June 10, 2016 22:35
Show Gist options
  • Save antonior92/2f2b1b855eec3a24537058ba84b84e5f to your computer and use it in GitHub Desktop.
Save antonior92/2f2b1b855eec3a24537058ba84b84e5f to your computer and use it in GitHub Desktop.
Give instructions to install Postgres on Mac OSX.

Install Postgres on Mac OSX

Install Postgres via Homebrew

Use homebrew to install postgres:

$ brew install postgresql

Create/Upgrade a database

If this is your first time installing Postgres with Homebrew, you'll need to create a database with:

$ initdb /usr/local/var/postgres -E utf8

Install Lunchy

Lunchy is a helpful gem that will allow you to easily start and stop Postgres.

$ gem install lunchy

to configure lunchy to do so one should use:

$ mkdir -p ~/Library/LaunchAgents
$ cp /usr/local/Cellar/postgresql/9.5.3/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/

Start/stop Postgres

To start postgres one should use:

$ lunchy start postgres

and to stop it:

$ lunchy stop postgres

Create an 'postgres' user

$ createuser -s postgres

Example 1: Creating a database with postgres as user

$ createdb -U postgres EXAMPLE

Example 2: Restore a database from 'example.backup'

$ pg_restore -d EXAMPLE -v example.backup 

Example 3: List all databases

$ psql -U postgres
$ \l

References:

  1. https://www.moncefbelyamani.com/how-to-install-postgresql-on-a-mac-with-homebrew-and-lunchy/

  2. http://stackoverflow.com/questions/15301826/psql-fatal-role-postgres-does-not-exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment