Skip to content

Instantly share code, notes, and snippets.

@ciniglio
Created November 15, 2012 06:50
Show Gist options
  • Save ciniglio/4077081 to your computer and use it in GitHub Desktop.
Save ciniglio/4077081 to your computer and use it in GitHub Desktop.
Installing postgres on mac for rails dev

Installation

Install Postgres and have it load on startup

sudo port install postgresql92-server
sudo port load postgresql92-server

Make needed dirs

sudo mkdir -p /opt/local/var/db/postgresql92/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql92/defaultdb
sudo mkdir -p /opt/local/var/log/postgresql92
sudo chown -R postgres:postgres /opt/local/var/log/postgresql92

Init the db

sudo su postgres -c '/opt/local/lib/postgresql92/bin/initdb -D /opt/local/var/db/postgresql92/defaultdb' 

Start running the db

sudo su - postgres
/opt/local/lib/postgresql92/bin/pg_ctl -D /opt/local/var/db/postgresql92/defaultdb -l /opt/local/var/log/postgresql92/logfile start

Add user 'fitacular' as superuser

/opt/local/lib/postgresql92/bin/createuser -s fitacular

You can now log out of postgres user (hit ctrl-d)

Create the db

/opt/local/lib/postgresql92/bin/createdb fitacular -U fitacular

get to psql prompt

/opt/local/lib/postgresql92/bin/psql -U fitacular

Integrating with Ruby

Add to your path, at least for now (can add to .bashrc or .zshrc to make it easier later)

export PATH=/opt/local/lib/postgresql92/bin/:$PATH

Make sure 'pg' gem is right, by uninstalling first!

gem uninstall pg

Get git changes and head to db branch

git checkout db && git pull

install pg gem with right extensions

bundle

Setup db and migrate

bundle exec rake db:create
bundle exec rake db:migrate
bundle exec rake db:populate

Now you're running with PG

NBD

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