I use a mac, currently running OS 10.6 / Snow Leopard, and I’d like to query our greenplum / postgres database from R. This used to work with R 2.9, but I unfortunately had to upgrade R, and R 2.10 on the mac is a 64 bit app. So, I want to use either RODBC or RPostgreSQL packages under 64 bit R on a mac to query postgres / greenplum.
First, I tried just installing RPostgreSQL as before. Unfortunately, I started getting weird errors when I attempted to load the package:
1 2 3 4 5 6 7 8 9
The key bit of the error message is the missing symbol:
_PQbackendPID. Some googling suggested this could be caused by mixing 32 and 64 bit libs. I used file to check and yes, indeed, I had a 32 bit version of Postgres that was refusing to talk to a 64 bit version on R. Suck.
In brief, the solution is to use
ports to install postgres — in this case, postgres 8.4 via
sudo port install postgres84
you can use the
file command to see what architecture your installed postgres is configured as:
checking, my previous postgres 8.4 install, from the Postgres Plus prebuild package, produces
1 2 3 4
Notice the lack of any 64bit support.
Then open a terminal, set the
PG_CONFIG environmental variable to point to the right location, then run R from the terminal and install the package.
1 2 3 4
If you have misconfigured the pg_config, this is the relevant bit of the compilation error message you will receive:
1 2 3 4
Otherwise, RPostgreSQL will compile and install. Seriously, though, there must be a better way of distributing software on macs.