一、安装postgres
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sudo yum install -y postgresql11-server
sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
sudo systemctl enable postgresql-11
sudo systemctl start postgresql-11
yum install -y postgresql11-libs postgresql11 postgresql11-devel
yum -y install postgresql11-contrib postgresql11-server
yum install gcc gcc-c++
二、安装openjdk
三、安装mvn
三、下载pljava,链接为git clone https://github.com/tada/pljava
cd pljava
mvn clean install(mvn -Dpgsql.pgconfig=/usr/pgsql-11/bin/pg_config clean install)
四、设置pljava.libjvm_location
cd /var/lib/pgsql/11/data/
pljava.libjvm_location=‘/usr/soft/openjdk11/lib/server/libjvm.so’
修改pg_hba.conf
自定义函数开发
package test;
public class function {
public static String hello(String str){
return "hello : " + str;
}
public static int arraycount(String[] arr){
return arr.length;
}
public static void main(String[] args) {
System.out.println(hello("123456"));
}
}
引用文件
select sqlj.install_jar(‘file:///pljava/pgjava.jar’,‘hello’,true);
更新jar包
— select sqlj.replace_jar(‘file:///pljava/pgjava.jar’,‘hello’,true);
Set schema下的类
select sqlj.set_classpath(‘public’,‘hello’);
创建function
create function sayhello(varchar) returns varchar as ‘test.function.hello’ language java;
drop function sayhello(varchar);