running-java-within-postgres comment
See original GitHub issueHi!
Thanks for the blog post about PL/Java. I noticed a couple of things that might allow it to be simplified.
- While your post says PL/Java is not available as a prebuilt package, as you are using debian in your example, in fact it is. If you enable the PostgreSQL debian repository, you can simply
apt-get install postgresql-server-9.6 postgresql-9.6-pljava
(along with whatever other packages you need at run time). There is then no need for maven, gcc, git, or any build-from-source process. - The debian package of PL/Java declares its own dependency on
default-java
, so that package will be pulled in if you don’t have it, without needing to be requested. - When using the debian package, there is no need for
SET pljava.libjvm_location
as the packager has compiled in a default value that refers to the normaldefault-java
package. Therefore, thepljava.libjvm_location
variable only needs to be set if you wish to run PL/Java with a different Java runtime than the default. - If the user
postgres
is a superuser in your database, there is no real need forGRANT USAGE ON LANGUAGE java TO postgres;
. - It might be worth mentioning that the
jdbc:default:connection
is not a conventional JDBC connection (it does not use PG’s network protocol to converse with the backend); it is simply a shim that presents direct internal access to the backend via the familiar JDBC API. - Code written for Java 7 or later would conventionally use try-with-resources when opening JDBC
Connection
s,Statement
s, orResultSet
s. (In PL/Java, forConnection
it doesn’t really matter, as that shim “connection” never closes anyway. But it is harmless, and forStatement
orResultSet
it can ensure resources are released.) - If a
@Function
annotation does not have acomment
attribute, but the function has a javadoc comment, the first sentence of the javadoc will be used as the SQL function comment.
But those are minor points. I think the post did quite a good job covering the basics.
A couple more direct links into the documentation that might be helpful are to the Hello, world example (which is much like your own example but has a “further reading” list at the bottom) and, for production environments, the VM option recommendations page: Java’s default VM options on a server machine kind of assume it has the machine to itself, and some tweaks to those options can greatly reduce its footprint when running in PostgreSQL.
Thanks for the coverage!
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Writing PostgreSQL functions with Java using PL/Java - rieckpil
Learn how to write PostgreSQL functions/stored procedures with Java using PL/Java. The example will use Debian 8, Java 8 and PostgreSQL ...
Read more >How to Connect PostgreSQL with Java Application - Virtuozzo
A guide on how to connect and manage PostgreSQL database server from the Java application server. Follow the steps to create an environment, ......
Read more >In JDBC for PostgreSQL, can I execute commands of psql?
1 Answer 1 ... The PostgreSQL JDBC driver does not use psql at all. It is implemented in Java and does not even...
Read more >Java Connect to PostgreSQL Database Example - YouTube
Learn to code a Java program that connects to PostgreSQL database server and execute SQL statements using JDBC ( Java Database Connectivity) ...
Read more >How to connect to PostgreSQL using JAVA JDBC - YouTube
Download source code here https://jinujawad.com/how-to-connect-to- postgresql - using - java -jdbc/Install postgress and pgadmin in windows ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You’re welcome. 😃 I noticed another thing:
To be honest, PL/Java doesn’t really care whether the URL is relative or absolute, certainly not enough to put “fully-qualified” in boldface.
would load
foo.jar
if it happened to be in the server’s current directory (thedatadir
). If you give a relativefile:
URL, you just have to know where the file is, relative to thedatadir
.You can also give an absolute
file:
URL using just one leading slash rather than three. Three slashes are just the//hostname/path
form where the hostname happens to be empty, meaning the local host, just the same as/path
.Cheers!
I see another possible refinement: 😃
A user with
USAGE
privilege on a language is able to create new functions that are written in that language.Once a function is created, any user with
EXECUTE
privilege on that function is able to use the function.Depending on your security requirements, you might want the same user to be able to create new functions and to use existing ones, or you might want an application user only to be able to execute existing functions, while reserving the privilege of creating functions to a different user, or even only to superusers (in which case no
GRANT USAGE
is needed).