Chapter 2. Installation

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
    make -f Makefile.pgxs
    make -f Makefile.pgxs install
   

Note: PL/R should build cleanly with PostgreSQL 7.3.x, 7.4.x, and 8.0.x. and R 1.6.2 and newer. The current release passed its regression test with R 2.0.1 under Fedora Core 2.

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;
   

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.

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), and then running ldconfig. Refer to man ldconfig or its equivalent for your system.

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.