Thursday, September 11, 2014

PL/Perl on PPAS 9.3 for *EL6

PL/Perl on Postgres Plus Advanced Server 9.3 

The version of Perl supported for Postgres Plus Advanced Server 9.3 is 5.14. "Enterprise Linux 6.5" distros come with Perl 5.10. Most users choose a precompiled Perl distribution from ActiveState. However, ActiveState changed their licensing model, and ActivePerl 5.14 is no longer available for a free download.

The steps below will get you up and running with pl/perl on PPAS 9.3 for RHEL6, OEL6, and CentOS 6.

Step 1: Download Perl from the Perl Archive Network 

[root@localhost tmp]# wget search.cpan.org/CPAN/authors/id/J/JE/JESSE/perl-5.14.0.tar.gz


Step 2: Decompress 


[root@localhost tmp]# gzip -d perl-5.14.0.tar.gz

Step 3: Extract 

[root@localhost tmp]# tar -xvf perl-5.14.0.tar


Step 4: Change current directory 


[root@localhost tmp]# cd perl-5.14.0


Step 5: Run the installation shell script 


[root@localhost perl-5.14.0]# ./Configure

Two non default options are needed, be sure to answer 'y' for 'Building a threading Perl', and 'y' to 'build a shared libperl.so'. This example changes the installation directory to /opt/perl514

Change the default installation directory (optional)
Installation prefix to use? (~name ok) [/usr/local] /opt/perl514

Answer 'y'
If this doesn't make any sense to you, just accept the default 'n'. Build a threading Perl? [n] y

Answer 'y'
Build a shared libperl.so (y/n) [n] y

Step 6: Compile


[root@localhost perl-5.14.0]# make test
[root@localhost perl-5.14.0]# make install


Step 7: Source 


-bash-4.1$ export LD_LIBRARY_PATH=/opt/perl514/lib/5.14.0/x86_64-linux-thread-multi/CORE:$LD_LIBRARY_PATH


Step 8: Restart the PPAS Cluster 

-bash-4.1$ pg_ctl restart -mf -D /opt/PostgresPlus/9.3AS/data/


Step 9: Create language in the desired database 


-bash-4.1$ ./bin/psql -c "create language plperl" geom_repo enterprisedb


Step 10: Test Pl/Perl using the example from EDB's plperl readme


    CREATE OR REPLACE FUNCTION perl_max (integer, integer) RETURNS integer AS
    $$
        if ($_[0] > $_[1])
          { return $_[0]; }
        return $_[1];
    $$ LANGUAGE plperl;

geom_repo=# select perl_max(1,2);
-[ RECORD 1 ]                    
perl_max | 2