Installing PL/R

PL/R is available as a package that you can download from the Pivotal Network and install using the Package Manager utility (gppkg).

Note: For details on how to use PL/R, see Using PL/R.

Prerequisites

Before you install the PL/R software package, ensure the following:

  • Your HAWQ cluster is up and running
  • You have sourced greenplum_path.sh
  • You have set the $GPHOME variable
  • Version of R used in PL/R is 3.1.0

Install PL/R

  1. Download the HDB Language Extensions tar.gz file from the Pivotal Network and extract its contents.
  2. Copy the PL/R package file to the HAWQ master host.
  3. On HAWQ master, install the software package by running the following command:

    $ gppkg -i plr-x.x.x.x-x86_64.gppkg
    

    where x.x.x.x corresponds to the version of the package file that you are installing.

  4. Source the $GPHOME/greenplum_path.sh file again. The extension and the R environment are installed in the $GPHOME/ext/R-N.N.N/ directory.

    where N.N.N corresponds to the version of PL/R installed. For example, $GPHOME/ext/R-3.1.0.

  5. Restart the cluster:

    $ hawq restart cluster
    

Enable PL/R Language Support

For each database that requires its use, register the PL/R language with the CREATE LANGUAGE SQL command.

As the gpadmin user, connect to the database that you wish to add PL/R language support. For example, to add support to a database named testdb:

$ psql -d testdb

In the psql prompt, run the DROP LANGUAGE SQL command to remove PL/R support:

psql> CREATE LANGUAGE plr;

You are now ready to create new PLR functions.

Install PL/R Functions

A library of existing, convenient PLR functions may be found in $GPHOME/share/postgresql/contrib/plr.sql.

Install these pre-existing PL/R functions by using the psql utility to execute plr.sql, as follows:

$ psql -d <dbname> -f $GPHOME/share/postgresql/contrib/plr.sql

Replace <dbname> with the name of the target database.

Note: This script also adds PL/R language support. You do not have to run the CREATE LANGUAGE plr SQL command on each database.

Downloading and Installing R Packages

R packages are modules that contain R functions and data sets. You can install R packages to extend R and PL/R functionality in HAWQ.

See Downloading and Installing R Packages

Note: If you expand HAWQ and add segment hosts, you must install the R packages in the R installation of the new hosts.

Uninstall PL/R

When you remove PL/R language support from a database, the PL/R routines that you created in the database will no longer work.

Remove PL/R Support for a Database

For a database that no longer requires the PL/R language, remove support for PL/R with the SQL command DROP LANGUAGE.

As the gpadmin user, connect to the database that you wish to remove PL/R language support. For example:

psql -d testdb

In the psql prompt, run the DROP LANGUAGE SQL command to remove PL/R support:

psql> DROP LANGUAGE plr;

If you have installed PLR functions included in plr.sql, then you must use the following command instead:

psql> DROP LANGUAGE plr CASCADE;

Uninstall the Software Package

If no databases have PL/R as a registered language, you can uninstall the PL/R extension pacakge with the gppkg utility.

To find out which version of the package you have installed, run the gppkg utility with the options -q --all to list the installed extensions and their versions. For example:

$ gppkg -q --all
plr-2.0.0.0

To uninstall the package, run the following command.

$ gppkg -r plr

Then, restart the cluster.

$ hawq restart cluster