To get PL/R working on OS X 10.7.4, I had to reach out to the PL/R community for assistance (note something like
sudo apt-get install postgresql-9.1-plr postgresql-server-dev-9.1 is all that is needed with Ubuntu). I just (on 2013-06-10) installed on a machine with Mac OS X 10.8.4 without any issue. One thing that is missing from the following, but included with the Kyngchaos version, is the idea of creating each version of PostgreSQL in separate directories (e.g.,
/usr/local/pgsql-9.1 with symlinks from
/usr/local/pgsql; this would seem to be easy to implement, but this is for the future.
1. Compiled PostgreSQL from source using flags shown when running pg_config from the Kyngchaos version (except I omitted –with-nls, due to its not working, and added –with-perl).
2. Compiled PL/R using variables from various sources (note that, by default, PostgreSQL ends up in the same place as it does with the Kyngchaos version).
3. Did the usual admin stuff to get PostgreSQL up and running and CREATE EXTENSION plr;
4. Restore my database from a backup.
0. Install Kyngchaos version of PostgreSQL.
I used to use a point-and-click installation available here (Kyngchaos gets a mention in PostgreSQL: Up and Running), even when ultimately installing from source. But I no longer think this step is necessary, as I think it was using the Kyngchaos installation to initialize the database cluster, but I am doing that myself now (see step 3 below).
1. Install PostgreSQL. I deleted the previously installed version of PostgreSQL by first unloading the LaunchDaemon loaded by the code at the bottom of this page and then nuking PostgreSQL by typing (for example)
sudo rm -rf /usr/local/pgsql-9.1 and
sudo rm -rf /usr/local/pgsql
cd ~ wget http://ftp.postgresql.org/pub/source/v9.2.4/postgresql-9.2.4.tar.gz tar xzf postgresql-9.2.4.tar.gz cd postgresql-9.2.4 ./configure --with-openssl --with-pam --with-krb5 --with-gssapi --with-ldap --enable-thread-safety --with-bonjour --with-python --with-perl --with-libxml make sudo make install
2. Install PL/R. Note that this step fails for me with the Kyngchaos version. I suspect this is because that version is compiled on a Mac with stuff in different places from where it is on my machine.
cd ~ wget http://www.joeconway.com/plr/plr-22.214.171.124.tar.gz tar xzf plr-126.96.36.199.tar.gz cd plr R_HOME="/Library/Frameworks/R.framework/Resources" USE_PGXS=1 PG_CONFIG="/usr/local/pgsql/bin/pg_config" make sudo R_HOME="/Library/Frameworks/R.framework/Resources" USE_PGXS=1 PG_CONFIG="/usr/local/pgsql/bin/pg_config" make install
3. Set up PostgreSQL
I first need to initialize the database cluster and then get the server running.
sudo mkdir /usr/local/pgsql/data sudo chown _postgres:_postgres /usr/local/pgsql/data sudo -u _postgres /usr/local/pgsql/bin/initdb -U _postgres -D /usr/local/pgsql/data/ --encoding=UTF8 --locale=en_US
I don’t think I need this:
sudo -u _postgres postgres -D /usr/local/pgsql/data/ &
I then adapted the following from the Kyngchaos and EnterpriseDB versions and saved it as /Library/LaunchDaemons/org.postgresql.postgres.plist (with ownership as root:wheel):
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>org.postgresql.postgres</string> <key>ProgramArguments</key> <array> <string>/usr/local/pgsql/bin/postmaster</string> <string>-D</string> <string>/usr/local/pgsql/data</string> </array> <key>RunAtLoad</key> <true/> <key>UserName</key> <string>postgres</string> <key>KeepAlive</key> <dict> <key>SuccessfulExit</key> <false/> </dict> </dict> </plist>
Then I got the database running and did some set-up to get PL/R going.
sudo launchctl load /Library/LaunchDaemons/org.postgresql.postgres.plist /usr/local/pgsql/bin/psql -U postgres -d template1
I tend to do my work using a database named “crsp” (originally I just had CRSP data in there) under my own user name. So I set stuff up accordingly. Within psql:
CREATE USER igow SUPERUSER PASSWORD 'xxxxx'; CREATE EXTENSION plr; CREATE DATABASE crsp OWNER igow; \q
4. Restore my database from a backup.
/usr/local/pgsql/bin/psql -U _postgres -d postgres -f /Volumes/2TB/data/pg/crsp_all.backup