PostgreSQL with pl/java pre-installed. Built using official PostgreSQL image.
1.2K
PL/Java is a PostgreSQL extension that allows us to
The latter allows us to create user-defined functions (UDF) and user-defined types (UDT). There is also limited support for foreign data wrappers (FDW).
I wrote a series of articles on how to use PL/Java back in 2011.
This extension creates a new JVM for each database connection. These docker images are configured (per PL/Java VM option recommendations) for improved performance albeit at the cost of making it impossible to attach to a running instance with a debugger.
We can get an additional performance boost by pre-compiling the java classes to native libraries
using the Java Ahead-of-Time Compiler (jaotc). The PL/Java documentation refers to
Quicker Clojure startup with AppCDS and AOT
for an example of this.
This docker image extends the official Postgres docker hub image extended to include the pljava procedural language. The image also installs pgTAP and pgxnclient.
pgTAP provides a TAP mechanism for PostgreSQL unit testing. It allows us to run tests in the database itself. It's useful when writing tests for stored procedures - and very useful when writing tests for java-based user-defined functions (UDF) and user-defined types (UDT).
PGXN is the PostgreSQL Extension Network. It provides a convenient way to find and manage PostgreSQL extensions. It should be checked before doing substantial work in PL/Java - there's no need to write new code if there's already a decent extension.
PGXS is used to build and register PGXN projects.
Yes - check the official PostgreSQL 'apt' repository. Some interesting projects are:
Debian packages
The Dockerfile installs the official pl/java package available at the PostgreSQL apt repo. The Dockerfile also installs pgTAP (for unit testing) and pgxnclient (PostGresql Extension Network) since anyone writing code in pl/java will definitely want to test it and is likely to be interested in additional extensions.
Finally the Dockerfile sets up a simple script that creates the 'java' extension and grants public access to 'java' (but not javau).
See the official PostgreSQL image page. This image does nothing but preinstall pl/java, pgTAP, and pgxnclient.
If you need the minimal viable command use
$ docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=password beargiles/pljava
A natural extension to this docker image is one that adds a /docker-entrypoint-initdb.d script
that defines pl/java-based stored procedures and any UDF/UDT that uses them.
It is possible to add your own java jars to the classpath and make the classes and methods available to the system. This is particularly useful when you wish to create opaque user-defined functions (UDF) user-defined types (UDT).
In this case you must add /usr/share/postgresql/14/pljava/pljava-api-1.6.4.jar to your claspath
and follow the restrictions listed on the pl/java wiki.
E.g., only static methods will be visible.
The Dockerfile will then need to be modified to:
/docker-entrypoint-initdb.d script using 'pgxs' to install the jar(s)At this point the custom jars will be available for use by any pl/java stored procedure.
The official list of prebuilt PL/Java distributions includes two additional docker images.
The source code ls located at github.com/beargiles/postgresql-pljava-docker.
Content type
Image
Digest
sha256:89193b600…
Size
239.4 MB
Last updated
over 3 years ago
docker pull beargiles/pljava