You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu22.04上PostgreSQL14.7安装PLJava时Maven构建失败求助

编译PL/Java时出现postgres.h找不到的错误

环境信息

Ubuntu 22.04系统,已安装以下软件并验证功能正常:

  • g++/gcc 11.3.0
  • OpenJDK 17.0.7
  • Maven 3.6.3
  • PostgreSQL 14.7
  • OpenSSL

g++版本

root@ubuntu:~# g++ --version
g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

gcc版本

root@ubuntu:~# gcc --version
gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Maven与Java版本

root@ubuntu:~# mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/apache-maven-3.6.3
Java version: 17.0.7, vendor: Microsoft, runtime: /usr/lib/jvm/msopenjdk-17-amd64
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.19.0-32-generic", arch: "amd64", family: "unix"

root@ubuntu:~# java -version
openjdk version "17.0.7" 2023-04-18 LTS
OpenJDK Runtime Environment Microsoft-7626293 (build 17.0.7+7-LTS)
OpenJDK 64-Bit Server VM Microsoft-7626293 (build 17.0.7+7-LTS, mixed mode, sharing)

PostgreSQL连接验证

可正常连接PostgreSQL服务:

#sudo -i -u postgres
postgres@ubuntu:~$ psql --host 192.168.176.128 --username postgres --dbname template1
Password for user postgres: 
psql (14.7 (Ubuntu 14.7-0ubuntu0.22.04.1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

template1=# 

pg_config输出

root@ubuntu:~# pg_config
BINDIR = /usr/lib/postgresql/14/bin
DOCDIR = /usr/share/doc/postgresql-doc-14
HTMLDIR = /usr/share/doc/postgresql-doc-14
INCLUDEDIR = /usr/include/postgresql
PKGINCLUDEDIR = /usr/include/postgresql
INCLUDEDIR-SERVER = /usr/include/postgresql/14/server
LIBDIR = /usr/lib/x86_64-linux-gnu
PKGLIBDIR = /usr/lib/postgresql/14/lib
LOCALEDIR = /usr/share/locale
MANDIR = /usr/share/postgresql/14/man
SHAREDIR = /usr/share/postgresql/14
SYSCONFDIR = /etc/postgresql-common
PGXS = /usr/lib/postgresql/14/lib/pgxs/src/makefiles/pgxs.mk
CONFIGURE =  '--build=x86_64-linux-gnu' '--prefix=/usr' '--includedir=${prefix}/include' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--disable-option-checking' '--disable-silent-rules' '--libdir=${prefix}/lib/x86_64-linux-gnu' '--runstatedir=/run' '--disable-maintainer-mode' '--disable-dependency-tracking' '--with-tcl' '--with-perl' '--with-python' '--with-pam' '--with-openssl' '--with-libxml' '--with-libxslt' '--mandir=/usr/share/postgresql/14/man' '--docdir=/usr/share/doc/postgresql-doc-14' '--sysconfdir=/etc/postgresql-common' '--datarootdir=/usr/share/' '--datadir=/usr/share/postgresql/14' '--bindir=/usr/lib/postgresql/14/bin' '--libdir=/usr/lib/x86_64-linux-gnu/' '--libexecdir=/usr/lib/postgresql/' '--includedir=/usr/include/postgresql/' '--with-extra-version= (Ubuntu 14.7-0ubuntu0.22.04.1)' '--enable-nls' '--enable-thread-safety' '--enable-debug' '--enable-dtrace' '--disable-rpath' '--with-uuid=e2fs' '--with-gnu-ld' '--with-gssapi' '--with-ldap' '--with-pgport=5432' '--with-system-tzdata=/usr/share/zoneinfo' 'AWK=mawk' 'MKDIR_P=/bin/mkdir -p' 'PROVE=/usr/bin/prove' 'PYTHON=/usr/bin/python3' 'TAR=/bin/tar' 'XSLTPROC=xsltproc --nonet' 'CFLAGS=-g -O2 -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer' 'LDFLAGS=-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now' '--enable-tap-tests' '--with-icu' '--with-llvm' 'LLVM_CONFIG=/usr/bin/llvm-config-14' 'CLANG=/usr/bin/clang-14' '--with-lz4' '--with-systemd' '--with-selinux' 'build_alias=x86_64-linux-gnu' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' 'CXXFLAGS=-g -O2 -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security'
CC = gcc
CPPFLAGS = -Wdate-time -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -I/usr/include/libxml2
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -Wno-stringop-truncation -g -g -O2 -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -fno-omit-frame-pointer
CFLAGS_SL = -fPIC
LDFLAGS = -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -L/usr/lib/llvm-14/lib -Wl,--as-needed
LDFLAGS_EX = 
LDFLAGS_SL = 
LIBS = -lpgcommon -lpgport -lselinux -llz4 -lxslt -lxml2 -lpam -lssl -lcrypto -lgssapi_krb5 -lz -lreadline -lm 
VERSION = PostgreSQL 14.7 (Ubuntu 14.7-0ubuntu0.22.04.1)
root@ubuntu:~# 

编译错误详情

将PLJava克隆至/root/pl目录,以root用户执行cd pl/pljava && mvn clean install命令时,编译PL/Java后端原生代码阶段失败,错误信息如下:

[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running PgConfigPropertyAsListTest
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.193 s - in PgConfigPropertyAsListTest
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ pljava-pgxs ---
[INFO] Building jar: /root/pl/pljava/pljava-pgxs/target/pljava-pgxs-2-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-plugin-plugin:3.6.0:addPluginArtifactMetadata (default-addPluginArtifactMetadata) @ pljava-pgxs ---
[INFO] 
[INFO] --- maven-site-plugin:3.9.1:attach-descriptor (attach-descriptor) @ pljava-pgxs ---
[INFO] Skipping because packaging 'maven-plugin' is not pom.
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ pljava-pgxs ---
[INFO] Installing /root/pl/pljava/pljava-pgxs/target/pljava-pgxs-2-SNAPSHOT.jar to /root/.m2/repository/org/postgresql/pljava-pgxs/2-SNAPSHOT/pljava-pgxs-2-SNAPSHOT.jar
[INFO] Installing /root/pl/pljava/pljava-pgxs/pom.xml to /root/.m2/repository/org/postgresql/pljava-pgxs/2-SNAPSHOT/pljava-pgxs-2-SNAPSHOT.pom
[INFO] 
[INFO] ----------------------< org.postgresql:pljava-so >----------------------
[INFO] Building PL/Java backend native code 2-SNAPSHOT                    [5/8]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ pljava-so ---
[INFO] 
[INFO] --- properties-maven-plugin:1.0.0:set-system-properties (default) @ pljava-so ---
[INFO] Set 1 system property
[INFO] 
[INFO] --- pljava-pgxs:2-SNAPSHOT:scripted-goal (build-shared-object) @ pljava-so ---
[INFO] Using compiling/linking rules for Linux
In file included from /root/pl/pljava/pljava-so/src/main/include/pljava/JNICalls.h:18,
                 from /root/pl/pljava/pljava-so/src/main/include/pljava/PgObject.h:16,
                 from /root/pl/pljava/pljava-so/src/main/include/pljava/Exception.h:18,
                 from /root/pl/pljava/pljava-so/src/main/c/type/byte_array.c:9:
/root/pl/pljava/pljava-so/src/main/include/pljava/pljava.h:33:10: fatal error: postgres.h: No such file or directory
   33 | #include <postgres.h>
      |          ^~~~~~~~~~~~
compilation terminated.
/root/pl/pljava/pljava-so/src/main/c/type/Void.c:13:10: fatal error: postgres.h: No such file or directory
   13 | #include <postgres.h>
      |          ^~~~~~~~~~~~
compilation terminated.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for PostgreSQL PL/Java 2-SNAPSHOT:
[INFO] 
[INFO] PostgreSQL PL/Java ................................. SUCCESS [01:58 min]
[INFO] PL/Java API ........................................ SUCCESS [ 53.809 s]
[INFO] PL/Java backend Java code .......................... SUCCESS [ 10.391 s]
[INFO] PL/Java PGXS ....................................... SUCCESS [01:52 min]
[INFO] PL/Java backend native code ........................ FAILURE [ 29.944 s]
[INFO] PL/Java Ant tasks .................................. SKIPPED
[INFO] PL/Java examples ................................... SKIPPED
[INFO] PL/Java packaging .................................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  05:26 min
[INFO] Finished at: 2023-04-29T05:19:00Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.postgresql:pljava-pgxs:2-SNAPSHOT:scripted-goal (build-shared-object) on project pljava-so: Compilation failed with exit code: 1 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :pljava-so

已尝试参考GitHub相关文档解决,但问题仍未解决,寻求帮助。


内容的提问来源于stack exchange,提问作者Debraj Bhowmik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 19:14:58