Querying Postgres or Greenplum From R on a Mac, Installation Instructions
NB: this works on 64b versions of R; I tested it with the R64 app with R version 2.10.1 on Snow Leopard
Step by step instructions for talking to Postgres or Greenplum:
- install macports
- install postgres; I used 8.4
sudo port install postgresql84
- in a shell, create an environmental variable PG_CONFIG pointing to the pg_config binary installed by postgres. In my installation, this is something like
export PG_CONFIG=/opt/local/lib/postgresql84/bin/pg_config
- in the same shell, tell R to install the RPostgreSQL package *from source*, ie
$ R > install.packages('RPostgreSQL', type='source') - test the installation works:
> library('RPostgreSQL') Loading required package: DBI > drv <- dbDriver('PostgreSQL') > db <- dbConnect(drv, host='greenplum.ip', user='earl', dbname='dbname') > dbGetQuery(db, 'select 1') ?column? 1 1
Diagnosing error messages / problems:
- If R says
Warning message: In install.packages("RPostgreSQL") : package ‘RPostgreSQL’ is not available
you must specify to install the package from source, as above with type=’source’ - If you get compilation errors when installing the package that mention libpq-fe.h, then R can’t find pg_config
- if the package installs but when loading it you get errors involving missing symbol _PQbackendPID then you are mixing 32 and 64 bit software.
Follow the links for instructions to fix your problems.