PL/Java on Gentoo

  1. Download the PL/Java source tarball from pgFoundry
  2. Ensure that you are not using JDK 1.6
    java-config -L
  3. If necessary, switch to JDK 1.5
    emerge -av “<sun-jdk-1.6”
    java-config -S sun-jdk-1.5
  4. Tinker with the PostgreSQL include files a bit
    cd /usr/include/postgresql
    mv pgsql pgsql.old
    ln -s libpq-4 pgsql
  5. Extract the PL/Java source tarball
  6. Execute make in the PL/Java source directory
  7. If necessary, switch back to your original JDK
    java-config -S <Your original JDK>
  8. Restore the PostgreSQL include files to their original state
    cd /usr/include/postgresql
    rm pgsql
    mv pgsql.old pgsql
  9. Determine the library directory used by Postgres and copy the PL/Java shared object to this location. On my environment this is /usr/lib64/postgresql:
    cp build/pljava.so `pg_config –pkglibdir`
  10. Ensure that the JVM library paths are properly set in /etc/env.d/20java. Supposedly, java-config –set-system-vm=sun-jdk-1.6 is intended to do this, but I don’t buy it. Here’s what mine looks like:
    # Autogenerated by java-config
    # Command: –set-system-vm=blackdown-jdk-1.4.2 

    LDPATH=/opt/sun-jdk-1.6.0.03/jre/lib/amd64/:/opt/sun-jdk-1.6.0.03/jre/lib/amd64/native_threads/:/opt/sun-jdk-1.6.0.03/jre/lib/amd64/server/

    JDK_HOME=/opt/sun-jdk-1.6.0.03
    JAVAC=/opt/sun-jdk-1.6.0.03/bin/javac
    GENERATION=2
    ROOTPATH=/opt/sun-jdk-1.6.0.03/bin:/opt/sun-jdk-1.6.0.03/jre/bin
    VMHANDLE=blackdown-jdk-1.4.2
    MANPATH=/opt/sun-jdk-1.6.0.03/man
    PATH=/opt/sun-jdk-1.6.0.03/bin:/opt/sun-jdk-1.6.0.03/jre/bin
    JAVA_HOME=/opt/sun-jdk-1.6.0.03

  11. Run env-update
  12. Download the PostgreSQL JDBC Driver
  13. Install the sqlj schema in some database or other
    cd build
    export CLASSPATH=./deploy.jar:/path/to/postgresql-*.jdbc4.jar 

    java org.postgresql.pljava.deploy.Deployer -install -host localhost
    -port 5432 -database mygreatdatabase -user postgres -password
    supersecretpassword