Place source tar file in contrib in the PostgreSQL source tree and untar it. The shared object for the R call handler is built and installed in the PostgreSQL library directory via the following commands (starting from /path/to/postgresql_source/contrib):
cd plr make make install
As of PostgreSQL 8.0.0, PL/R can also be built without the PostgreSQL source tree. Untar PL/R whereever you prefer. The shared object for the R call handler is built and installed in the PostgreSQL library directory via the following commands (starting from /path/to/plr):
cd plr USE_PGXS=1 make USE_PGXS=1 make install
Win32 - adjust paths according to your own setup, and be sure to restart the PostgreSQL service after changing:
In Windows environment: R_HOME=C:\Progra~1\R\R-2.5.0 Path=%PATH%;C:\Progra~1\R\R-2.5.0\bin In MSYS: export R_HOME=/c/progra~1/R/R-2.5.0 export PATH=$PATH:/c/progra~1/PostgreSQL/8.2/bin USE_PGXS=1 make USE_PGXS=1 make install
You can use plr.sql (which is created in contrib/plr) to create the language and support functions in your database of choice:
psql mydatabase < plr.sql
Alternatively you can create the language manually using SQL commands:
CREATE FUNCTION plr_call_handler() RETURNS LANGUAGE_HANDLER AS '$libdir/plr' LANGUAGE C; CREATE LANGUAGE plr HANDLER plr_call_handler;
As of PostgreSQL 9.1 you can use the new CREATE EXTENSION command:
CREATE EXTENSION plr;
This is not only simple, it has the added advantage of tracking all PL/R installed objects as dependent on the extension, and therefore they can be removed just as easily if desired:
DROP EXTENSION plr;
Tip: If a language is installed into template1, all subsequently created databases will have the language installed automatically.
Tip: In addition to the documentation, the plr.out.* files in plr/expected are a good source of usage examples.
Tip: R headers are required. Download and install R prior to building PL/R. R must have been built with the --enable-R-shlib option when it was configured, in order for the libR shared object library to be available.
Tip: Additionally, libR must be findable by your runtime linker. On Linux, this involves adding an entry in /etc/ld.so.conf for the location of libR (typically $R_HOME/bin or $R_HOME/lib), and then running ldconfig. Refer to man ldconfig or its equivalent for your system.
Tip: R_HOME must be defined in the environment of the user under which PostgreSQL is started, before the postmaster is started. Otherwise PL/R will refuse to load. See plr_environ(), which allows examination of the environment available to the PostgreSQL postmaster process.