A PostgreSQL Cheat Sheet for OSX and R

2015-01-23

I keep this on my desktop.

Install:

brew install postgresql
initdb /usr/local/var/postgres -E utf8
gem install lunchy
### Start postgres with lunchy
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.3.3/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/

Setup DB from SQL file:

### Setup DB
lunchy start postgres
created $DBNAME
psql -d $DBNAME -f '/path/to/file.sql'
lunchy stop postgres

Starting and Stopping PostgreSQL

lunchy start postgres
lunchy stop postgres

may run into trouble with local socket… try this:

rm /usr/local/var/postgres/postmaster.pid

Connecting with R

# make sure lunch start postgres in terminal first)
require(dplyr)
db <- src_postgres(dbname=$DBNAME)

Inspired by seeing this post and thought I should toss out what I do.

This entry was tagged as rstats posgresql osx

blog comments powered by Disqus