2.3 源码编译安装PostgreSQL
2.3.1 下载并解压缩源码包
PostgreSQL源码包下载,去“https://www.postgresql.org/ftp/source”网站下载,根据需要的版本下载,比如这里下载:v17.6。

图6 下载PostgreSQL源码包
然后下载源码包“postgresql-17.6.tar.gz”。

图7 下载PostgreSQL源码包
# Rocky、Almalinux、CentOS、AnolisOS、OpenCloudOS、Kylin Server默认没有wget包,需要安装 yum install -y wget # openEuler 22.03/24.03 LTS、AnolisOS 23、OpenCloudOS 9没有安装tar包,需要安装 yum install -y tar cd /usr/local/src # 下载解压缩 wget https://ftp.postgresql.org/pub/source/v17.6/postgresql-17.6.tar.gz tar xf postgresql-17.6.tar.gz 2.3.2 源码编译安装PostgreSQL
编译安装参数解释:
./configure # 准备PostgreSQL的编译环境 --prefix # 指定 PostgreSQL 安装目录 --with-openssl # 启用 OpenSSL 支持 --with-libxml # 启用 XML 支持 --with-systemd # 启用 Systemd 支持 2.3.2.1 Rocky 8/9/10、AlmaLinux 8/9/10、CentOS 7、CentOS Stream 8/9/10、OpenCloudOS 8
进入PostgreSQL包解压的目录:
cd postgresql-17.6 执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: no acceptable C compiler found in $PATH # 提示,在$PATH中找不到可接受的C编译器,需要安装gcc See `config.log' for more details 安装gcc包:
yum install -y gcc 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for icu-uc icu-i18n... no configure: error: ICU library not found # 提示,未找到 ICU 库 If you have ICU already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-icu to disable ICU support. 安装libicu-devel包:
yum install -y libicu-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for bison... no configure: error: bison not found # 提示,未找到bison 安装bison包:
yum install -y bison 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for flex... no configure: error: flex not found # 提示,未找到flex 安装flex包:
yum install -y flex 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for perl... no configure: error: Perl not found # 提示,未找到Perl 安装perl包:
yum install -y perl 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for library containing readline... no configure: error: readline library not found # 提示,未找到readline库 If you have readline already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-readline to disable readline support. 安装readline-devel包:
yum install -y readline-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: zlib library not found # 提示,为找到zlib库 If you have zlib already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-zlib to disable zlib support. 安装zlib-devel包:
yum install -y zlib-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for CRYPTO_new_ex_data in -lcrypto... no configure: error: library 'crypto' is required for OpenSSL # 提示,需要库 'crypto' 来支持 OpenSSL 安装openssl-devel包:
yum install -y openssl-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for xmlSaveToBuffer in -lxml2... no configure: error: library 'xml2' (version >= 2.6.23) is required for XML support # 提示,需要库 'xml2'(版本 >= 2.6.23)以支持 XML 安装libxml2-devel包:
yum install -y libxml2-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: header file <systemd/sd-daemon.h> is required for systemd support # 提示,需要头文件 <systemd/sd-daemon.h> 以支持 systemd 安装systemd-devel包:
yum install -y systemd-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd 执行make:
# 默认 make 不包括文档和其它模块,$(nproc)表示当产主机的CPU核心 make -j $(nproc) world ... make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/test/isolation' make -C test/perl all make[2]: Entering directory '/usr/local/src/postgresql-17.6/src/test/perl' make[2]: Nothing to be done for 'all'. make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/test/perl' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/src' 执行make install:
# 默认 make install 不包括安装文档 make install-world ... make[3]: *** [Makefile:72: postgres-full.xml] Error 1 make[3]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src/sgml' make[2]: *** [Makefile:8: install] Error 2 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src' make[1]: *** [Makefile:16: install] Error 2 make[1]: Leaving directory '/usr/local/src/postgresql-17.6/doc' make: *** [GNUmakefile:32: install-world-doc-recurse] Error 2 yum install -y docbook-dtds docbook-style-xsl libxslt 重新执行make install:
make install-world 。。。 /usr/bin/mkdir -p '/apps/pgsql/lib' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/install -c -m 755 pgxml.so '/apps/pgsql/lib/pgxml.so' /usr/bin/install -c -m 644 ./xml2.control '/apps/pgsql/share/extension/' /usr/bin/install -c -m 644 ./xml2--1.1.sql ./xml2--1.0--1.1.sql '/apps/pgsql/share/extension/' make[2]: Leaving directory '/usr/local/src/postgresql-17.6/contrib/xml2' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/contrib' 总结编译过程:
# 安装依赖包 yum install -y gcc libicu-devel bison flex perl readline-devel zlib-devel openssl-devel libxml2-devel systemd-devel docbook-dtds docbook-style-xsl libxslt # 进入PostgreSQL包解压的目录: cd postgresql-17.6 # 执行configure ./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd # 执行make make -j $(nproc) world # 执行make install make install-world 2.3.2.2 openEuler 22.03/24.03 LTS
进入PostgreSQL包解压的目录:
cd postgresql-17.6 执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: no acceptable C compiler found in $PATH # 提示,在$PATH中找不到可接受的C编译器,需要安装gcc See `config.log' for more details 安装gcc包:
yum install -y gcc 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for icu-uc icu-i18n... no configure: error: ICU library not found # 提示,未找到 ICU 库 If you have ICU already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-icu to disable ICU support. 安装libicu-devel包:
yum install -y libicu-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for bison... no configure: error: bison not found # 提示,未找到bison 安装bison包:
yum install -y bison 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for flex... no configure: error: flex not found # 提示,未找到flex 安装flex包:
yum install -y flex 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for library containing readline... no configure: error: readline library not found # 提示,未找到readline库 If you have readline already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-readline to disable readline support. 安装readline-devel包:
yum install -y readline-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: zlib library not found # 提示,为找到zlib库 If you have zlib already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-zlib to disable zlib support. 安装zlib-devel包:
yum install -y zlib-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for CRYPTO_new_ex_data in -lcrypto... no configure: error: library 'crypto' is required for OpenSSL # 提示,需要库 'crypto' 来支持 OpenSSL 安装openssl-devel包:
yum install -y openssl-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for xmlSaveToBuffer in -lxml2... no configure: error: library 'xml2' (version >= 2.6.23) is required for XML support # 提示,需要库 'xml2'(版本 >= 2.6.23)以支持 XML 安装libxml2-devel包:
yum install -y libxml2-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: header file <systemd/sd-daemon.h> is required for systemd support # 提示,需要头文件 <systemd/sd-daemon.h> 以支持 systemd 安装systemd-devel包:
yum install -y systemd-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd 执行make:
# 默认 make 不包括文档和其它模块,$(nproc)表示当产主机的CPU核心 make -j $(nproc) world ... make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/test/isolation' make -C test/perl all make[2]: Entering directory '/usr/local/src/postgresql-17.6/src/test/perl' make[2]: Nothing to be done for 'all'. make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/test/perl' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/src' 执行make install:
# 默认 make install 不包括安装文档 make install-world ... make[3]: *** [Makefile:72: postgres-full.xml] Error 1 make[3]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src/sgml' make[2]: *** [Makefile:8: install] Error 2 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src' make[1]: *** [Makefile:16: install] Error 2 make[1]: Leaving directory '/usr/local/src/postgresql-17.6/doc' make: *** [GNUmakefile:32: install-world-doc-recurse] Error 2 yum install -y docbook-dtds docbook-style-xsl libxslt 重新执行make install:
make install-world ... ERROR: `xsltproc' is missing on your system. *** make[3]: *** [Makefile:130: html-stamp] Error 1 make[3]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src/sgml' make[2]: *** [Makefile:8: install] Error 2 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src' make[1]: *** [Makefile:16: install] Error 2 make[1]: Leaving directory '/usr/local/src/postgresql-17.6/doc' make: *** [GNUmakefile:32: install-world-doc-recurse] Error 2 重新执行configure:
# 再次执行make之前先清理之前的操作 make clean ./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd 执行make:
make -j $(nproc) world 重新执行make install:
make install-world 。。。 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/contrib/sslinfo' make -C xml2 install make[2]: Entering directory '/usr/local/src/postgresql-17.6/contrib/xml2' /usr/bin/mkdir -p '/apps/pgsql/lib' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/install -c -m 755 pgxml.so '/apps/pgsql/lib/pgxml.so' /usr/bin/install -c -m 644 ./xml2.control '/apps/pgsql/share/extension/' /usr/bin/install -c -m 644 ./xml2--1.1.sql ./xml2--1.0--1.1.sql '/apps/pgsql/share/extension/' make[2]: Leaving directory '/usr/local/src/postgresql-17.6/contrib/xml2' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/contrib' 总结编译过程:
# 安装依赖包 yum install -y gcc libicu-devel bison flex readline-devel zlib-devel openssl-devel libxml2-devel systemd-devel docbook-dtds docbook-style-xsl libxslt # 进入PostgreSQL包解压的目录: cd postgresql-17.6 # 执行configure ./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd # 执行make make -j $(nproc) world # 执行make install make install-world 2.3.2.3 AnolisOS 23
进入PostgreSQL包解压的目录:
cd postgresql-17.6 执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: no acceptable C compiler found in $PATH # 提示,在$PATH中找不到可接受的C编译器,需要安装gcc See `config.log' for more details 安装gcc包:
yum install -y gcc 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for icu-uc icu-i18n... no configure: error: ICU library not found # 提示,未找到 ICU 库 If you have ICU already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-icu to disable ICU support. 安装libicu-devel包:
yum install -y libicu-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for bison... no configure: error: bison not found # 提示,未找到bison 安装bison包:
yum install -y bison 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for flex... no configure: error: flex not found # 提示,未找到flex 安装flex包:
yum install -y flex 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for library containing readline... no configure: error: readline library not found # 提示,未找到readline库 If you have readline already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-readline to disable readline support. 安装readline-devel包:
yum install -y readline-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: zlib library not found # 提示,为找到zlib库 If you have zlib already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-zlib to disable zlib support. 安装zlib-devel包:
yum install -y zlib-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for CRYPTO_new_ex_data in -lcrypto... no configure: error: library 'crypto' is required for OpenSSL # 提示,需要库 'crypto' 来支持 OpenSSL 安装openssl-devel包:
yum install -y openssl-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for xmlSaveToBuffer in -lxml2... no configure: error: library 'xml2' (version >= 2.6.23) is required for XML support # 提示,需要库 'xml2'(版本 >= 2.6.23)以支持 XML 安装libxml2-devel包:
yum install -y libxml2-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: header file <systemd/sd-daemon.h> is required for systemd support # 提示,需要头文件 <systemd/sd-daemon.h> 以支持 systemd 安装systemd-devel包:
yum install -y systemd-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd 执行make:
# 默认 make 不包括文档和其它模块,$(nproc)表示当产主机的CPU核心 make -j $(nproc) world ... Can't locate FindBin.pm in @INC (you may need to install the FindBin module) (@INC contains: /usr/local/lib64/perl5/5.36 /usr/local/share/perl5/5.36 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at gen_node_support.pl line 24. # 提示,perl缺少FindBin.pm模块 BEGIN failed--compilation aborted at gen_node_support.pl line 24. Can't locate FindBin.pm in @INC (you may need to install the FindBin module) (@INC contains: /usr/local/lib64/perl5/5.36 /usr/local/share/perl5/5.36 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at ../../../src/backend/catalog/genbki.pl line 20. BEGIN failed--compilation aborted at ../../../src/backend/catalog/genbki.pl line 20. make[2]: *** [Makefile:141: bki-stamp] Error 2 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/include/catalog' make[1]: *** [Makefile:121: submake-catalog-headers] Error 2 make[1]: *** Waiting for unfinished jobs.... make[2]: *** [Makefile:78: node-support-stamp] Error 2 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/backend/nodes' make[1]: *** [Makefile:125: submake-nodes-headers] Error 2 make[1]: Leaving directory '/usr/local/src/postgresql-17.6/src/backend' make: *** [src/Makefile.global:384: submake-generated-headers] Error 2 安装perl-FindBin和perl-core包:
yum install -y perl-FindBin perl-core 执行make:
make -j $(nproc) world 执行make install:
# 默认 make install 不包括安装文档 make install-world ... make[3]: *** [Makefile:72: postgres-full.xml] Error 1 make[3]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src/sgml' make[2]: *** [Makefile:8: install] Error 2 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src' make[1]: *** [Makefile:16: install] Error 2 make[1]: Leaving directory '/usr/local/src/postgresql-17.6/doc' make: *** [GNUmakefile:32: install-world-doc-recurse] Error 2 yum install -y docbook-dtds docbook-style-xsl libxslt 重新执行configure:
# 再次执行make之前先清理之前的操作 make clean ./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd 执行make:
make -j $(nproc) world 重新执行make install:
make install-world 。。。 /usr/bin/mkdir -p '/apps/pgsql/lib' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/install -c -m 755 pgxml.so '/apps/pgsql/lib/pgxml.so' /usr/bin/install -c -m 644 ./xml2.control '/apps/pgsql/share/extension/' /usr/bin/install -c -m 644 ./xml2--1.1.sql ./xml2--1.0--1.1.sql '/apps/pgsql/share/extension/' make[2]: Leaving directory '/usr/local/src/postgresql-17.6/contrib/xml2' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/contrib' 总结编译过程:
# 安装依赖包 yum install -y gcc libicu-devel bison flex readline-devel zlib-devel openssl-devel libxml2-devel systemd-devel perl-FindBin perl-core docbook-dtds docbook-style-xsl libxslt # 进入PostgreSQL包解压的目录: cd postgresql-17.6 # 执行configure ./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd # 执行make make -j $(nproc) world # 执行make install make install-world 2.3.2.4 AnolisOS 8
进入PostgreSQL包解压的目录:
cd postgresql-17.6 执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: no acceptable C compiler found in $PATH # 提示,在$PATH中找不到可接受的C编译器,需要安装gcc See `config.log' for more details 安装gcc包:
yum install -y gcc 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for icu-uc icu-i18n... no configure: error: ICU library not found # 提示,未找到 ICU 库 If you have ICU already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-icu to disable ICU support. 安装libicu-devel包:
yum install -y libicu-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for bison... no configure: error: bison not found # 提示,未找到bison 安装bison包:
yum install -y bison 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for flex... no configure: error: flex not found # 提示,未找到flex 安装flex包:
yum install -y flex 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for library containing readline... no configure: error: readline library not found # 提示,未找到readline库 If you have readline already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-readline to disable readline support. 安装readline-devel包:
yum install -y readline-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: zlib library not found # 提示,为找到zlib库 If you have zlib already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-zlib to disable zlib support. 安装zlib-devel包:
yum install -y zlib-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for CRYPTO_new_ex_data in -lcrypto... no configure: error: library 'crypto' is required for OpenSSL # 提示,需要库 'crypto' 来支持 OpenSSL 安装openssl-devel包:
yum install -y openssl-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for xmlSaveToBuffer in -lxml2... no configure: error: library 'xml2' (version >= 2.6.23) is required for XML support # 提示,需要库 'xml2'(版本 >= 2.6.23)以支持 XML 安装libxml2-devel包:
yum install -y libxml2-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: header file <systemd/sd-daemon.h> is required for systemd support # 提示,需要头文件 <systemd/sd-daemon.h> 以支持 systemd 安装systemd-devel包:
yum install -y systemd-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd 执行make:
yum install -y make # 默认 make 不包括文档和其它模块,$(nproc)表示当产主机的CPU核心 make -j $(nproc) world ... make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/test/isolation' make -C test/perl all make[2]: Entering directory '/usr/local/src/postgresql-17.6/src/test/perl' make[2]: Nothing to be done for 'all'. make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/test/perl' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/src' 执行make install:
# 默认 make install 不包括安装文档 make install-world ... make[3]: *** [Makefile:72: postgres-full.xml] Error 1 make[3]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src/sgml' make[2]: *** [Makefile:8: install] Error 2 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src' make[1]: *** [Makefile:16: install] Error 2 make[1]: Leaving directory '/usr/local/src/postgresql-17.6/doc' make: *** [GNUmakefile:32: install-world-doc-recurse] Error 2 yum install -y docbook-dtds docbook-style-xsl libxslt 重新执行make install:
make install-world 。。。 /usr/bin/mkdir -p '/apps/pgsql/lib' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/install -c -m 755 pgxml.so '/apps/pgsql/lib/pgxml.so' /usr/bin/install -c -m 644 ./xml2.control '/apps/pgsql/share/extension/' /usr/bin/install -c -m 644 ./xml2--1.1.sql ./xml2--1.0--1.1.sql '/apps/pgsql/share/extension/' make[2]: Leaving directory '/usr/local/src/postgresql-17.6/contrib/xml2' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/contrib' 总结编译过程:
# 安装依赖包 yum install -y gcc libicu-devel bison flex readline-devel zlib-devel openssl-devel libxml2-devel systemd-devel make docbook-dtds docbook-style-xsl libxslt # 进入PostgreSQL包解压的目录: cd postgresql-17.6 # 执行configure ./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd # 执行make make -j $(nproc) world # 执行make install make install-world 2.3.2.5 OpenCloudOS 9、Kylin Server V10/V11
进入PostgreSQL包解压的目录:
cd postgresql-17.6 执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: no acceptable C compiler found in $PATH # 提示,在$PATH中找不到可接受的C编译器,需要安装gcc See `config.log' for more details 安装gcc包:
yum install -y gcc 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for icu-uc icu-i18n... no configure: error: ICU library not found # 提示,未找到 ICU 库 If you have ICU already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-icu to disable ICU support. 安装libicu-devel包:
yum install -y libicu-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for bison... no configure: error: bison not found # 提示,未找到bison 安装bison包:
yum install -y bison 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for flex... no configure: error: flex not found # 提示,未找到flex 安装flex包:
yum install -y flex 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for perl... no configure: error: Perl not found # 提示,未找到Perl 安装perl包:
yum install -y perl 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for library containing readline... no configure: error: readline library not found # 提示,未找到readline库 If you have readline already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-readline to disable readline support. 安装readline-devel包:
yum install -y readline-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: zlib library not found # 提示,为找到zlib库 If you have zlib already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-zlib to disable zlib support. 安装zlib-devel包:
yum install -y zlib-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for CRYPTO_new_ex_data in -lcrypto... no configure: error: library 'crypto' is required for OpenSSL # 提示,需要库 'crypto' 来支持 OpenSSL 安装openssl-devel包:
yum install -y openssl-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for xmlSaveToBuffer in -lxml2... no configure: error: library 'xml2' (version >= 2.6.23) is required for XML support # 提示,需要库 'xml2'(版本 >= 2.6.23)以支持 XML 安装libxml2-devel包:
yum install -y libxml2-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: header file <systemd/sd-daemon.h> is required for systemd support # 提示,需要头文件 <systemd/sd-daemon.h> 以支持 systemd 安装systemd-devel包:
yum install -y systemd-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd 执行make:
# 默认 make 不包括文档和其它模块,$(nproc)表示当产主机的CPU核心 make -j $(nproc) world ... make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/test/isolation' make -C test/perl all make[2]: Entering directory '/usr/local/src/postgresql-17.6/src/test/perl' make[2]: Nothing to be done for 'all'. make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/test/perl' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/src' 执行make install:
# 默认 make install 不包括安装文档 make install-world ... make[3]: *** [Makefile:72: postgres-full.xml] Error 1 make[3]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src/sgml' make[2]: *** [Makefile:8: install] Error 2 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src' make[1]: *** [Makefile:16: install] Error 2 make[1]: Leaving directory '/usr/local/src/postgresql-17.6/doc' make: *** [GNUmakefile:32: install-world-doc-recurse] Error 2 yum install -y docbook-dtds docbook-style-xsl libxslt 重新执行make install:
make install-world ... ERROR: `xsltproc' is missing on your system. *** make[3]: *** [Makefile:130: html-stamp] Error 1 make[3]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src/sgml' make[2]: *** [Makefile:8: install] Error 2 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src' make[1]: *** [Makefile:16: install] Error 2 make[1]: Leaving directory '/usr/local/src/postgresql-17.6/doc' make: *** [GNUmakefile:32: install-world-doc-recurse] Error 2 重新执行configure:
# 再次执行make之前先清理之前的操作 make clean ./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd 执行make:
make -j $(nproc) world 重新执行make install:
make install-world 。。。 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/contrib/sslinfo' make -C xml2 install make[2]: Entering directory '/usr/local/src/postgresql-17.6/contrib/xml2' /usr/bin/mkdir -p '/apps/pgsql/lib' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/install -c -m 755 pgxml.so '/apps/pgsql/lib/pgxml.so' /usr/bin/install -c -m 644 ./xml2.control '/apps/pgsql/share/extension/' /usr/bin/install -c -m 644 ./xml2--1.1.sql ./xml2--1.0--1.1.sql '/apps/pgsql/share/extension/' make[2]: Leaving directory '/usr/local/src/postgresql-17.6/contrib/xml2' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/contrib' 总结编译过程:
# 安装依赖包 yum install -y gcc libicu-devel bison flex perl readline-devel zlib-devel openssl-devel libxml2-devel systemd-devel docbook-dtds docbook-style-xsl libxslt # 进入PostgreSQL包解压的目录: cd postgresql-17.6 # 执行configure ./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd # 执行make make -j $(nproc) world # 执行make install make install-world 2.3.2.6 UOS Server V20
进入PostgreSQL包解压的目录:
cd postgresql-17.6 执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for icu-uc icu-i18n... no configure: error: ICU library not found # 提示,未找到 ICU 库 If you have ICU already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-icu to disable ICU support. 安装libicu-devel包:
yum install -y libicu-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for bison... no configure: error: bison not found # 提示,未找到bison 安装bison包:
yum install -y bison 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for flex... no configure: error: flex not found # 提示,未找到flex 安装flex包:
yum install -y flex 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for library containing readline... no configure: error: readline library not found # 提示,未找到readline库 If you have readline already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-readline to disable readline support. 安装readline-devel包:
yum install -y readline-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: header file <systemd/sd-daemon.h> is required for systemd support # 提示,需要头文件 <systemd/sd-daemon.h> 以支持 systemd 安装systemd-devel包:
yum install -y systemd-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd 执行make:
# 默认 make 不包括文档和其它模块,$(nproc)表示当产主机的CPU核心 make -j $(nproc) world ... make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/test/isolation' make -C test/perl all make[2]: Entering directory '/usr/local/src/postgresql-17.6/src/test/perl' make[2]: Nothing to be done for 'all'. make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/test/perl' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/src' 执行make install:
# 默认 make install 不包括安装文档 make install-world ... make[3]: *** [Makefile:72: postgres-full.xml] Error 1 make[3]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src/sgml' make[2]: *** [Makefile:8: install] Error 2 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src' make[1]: *** [Makefile:16: install] Error 2 make[1]: Leaving directory '/usr/local/src/postgresql-17.6/doc' make: *** [GNUmakefile:32: install-world-doc-recurse] Error 2 yum install -y docbook-dtds docbook-style-xsl libxslt 重新执行make install:
make install-world 。。。 /usr/bin/mkdir -p '/apps/pgsql/lib' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/install -c -m 755 pgxml.so '/apps/pgsql/lib/pgxml.so' /usr/bin/install -c -m 644 ./xml2.control '/apps/pgsql/share/extension/' /usr/bin/install -c -m 644 ./xml2--1.1.sql ./xml2--1.0--1.1.sql '/apps/pgsql/share/extension/' make[2]: Leaving directory '/usr/local/src/postgresql-17.6/contrib/xml2' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/contrib' 总结编译过程:
# 安装依赖包 yum install -y libicu-devel bison flex perl readline-devel systemd-devel docbook-dtds docbook-style-xsl libxslt # 进入PostgreSQL包解压的目录: cd postgresql-17.6 # 执行configure ./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd # 执行make make -j $(nproc) world # 执行make install make install-world 2.3.2.7 openSUSE 15
进入PostgreSQL包解压的目录:
cd postgresql-17.6 执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: no acceptable C compiler found in $PATH # 提示,在$PATH中找不到可接受的C编译器,需要安装gcc See `config.log' for more details 安装gcc包:
zypper install -y gcc 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for icu-uc icu-i18n... no configure: error: ICU library not found # 提示,未找到 ICU 库 If you have ICU already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-icu to disable ICU support. 安装libicu-devel包:
zypper install -y libicu-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for bison... no configure: error: bison not found # 提示,未找到bison 安装bison包:
zypper install -y bison 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for flex... no configure: error: flex not found # 提示,未找到flex 安装flex包:
zypper install -y flex 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for library containing readline... no configure: error: readline library not found # 提示,未找到readline库 If you have readline already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-readline to disable readline support. 安装readline-devel包:
zypper install -y readline-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: zlib library not found # 提示,为找到zlib库 If you have zlib already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-zlib to disable zlib support. 安装zlib-devel包:
zypper install -y zlib-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for CRYPTO_new_ex_data in -lcrypto... no configure: error: library 'crypto' is required for OpenSSL # 提示,需要库 'crypto' 来支持 OpenSSL 安装openssl-devel包:
zypper install -y openssl-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for xmlSaveToBuffer in -lxml2... no configure: error: library 'xml2' (version >= 2.6.23) is required for XML support # 提示,需要库 'xml2'(版本 >= 2.6.23)以支持 XML 安装libxml2-devel包:
zypper install -y libxml2-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: header file <systemd/sd-daemon.h> is required for systemd support # 提示,需要头文件 <systemd/sd-daemon.h> 以支持 systemd 安装systemd-devel包:
zypper install -y systemd-devel 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd 执行make:
zypper install -y make # 默认 make 不包括文档和其它模块,$(nproc)表示当产主机的CPU核心 make -j $(nproc) world ... make[3]: *** [Makefile:72: postgres-full.xml] Error 1 make[3]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src/sgml' make[2]: *** [Makefile:8: all] Error 2 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src' make[1]: *** [Makefile:16: all] Error 2 make[1]: Leaving directory '/usr/local/src/postgresql-17.6/doc' make: *** [GNUmakefile:16: world-doc-recurse] Error 2 zypper install -y docbook-xsl-stylesheets 重新执行configure:
# 再次执行make之前先清理之前的操作 make clean ./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd 重新执行make:
make -j $(nproc) world 执行make install:
# 默认 make install 不包括安装文档 make install-world 。。。 /usr/bin/mkdir -p '/apps/pgsql/lib' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/install -c -m 755 pgxml.so '/apps/pgsql/lib/pgxml.so' /usr/bin/install -c -m 644 ./xml2.control '/apps/pgsql/share/extension/' /usr/bin/install -c -m 644 ./xml2--1.1.sql ./xml2--1.0--1.1.sql '/apps/pgsql/share/extension/' make[2]: Leaving directory '/usr/local/src/postgresql-17.6/contrib/xml2' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/contrib' 总结编译过程:
# 安装依赖包 zypper install -y gcc libicu-devel bison flex readline-devel zlib-devel openssl-devel libxml2-devel systemd-devel make docbook-xsl-stylesheets # 进入PostgreSQL包解压的目录: cd postgresql-17.6 # 执行configure ./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd # 执行make make -j $(nproc) world # 执行make install make install-world 2.3.2.8 Ubuntu Server 20.04/22.04/24.04 LTS、Debian 11/12/13
进入PostgreSQL包解压的目录:
cd postgresql-17.6 执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: no acceptable C compiler found in $PATH # 提示,在$PATH中找不到可接受的C编译器,需要安装gcc See `config.log' for more details 安装gcc包:
apt install -y gcc 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for pkg-config... no # 没有检测到pkg-config,要安装pkg-config,否则还会出现报错 checking whether to build with ICU support... yes checking for icu-uc icu-i18n... no configure: error: ICU library not found # 提示,未找到 ICU 库 If you have ICU already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-icu to disable ICU support. 安装pkg-config和libicu-dev包:
apt install -y pkg-config libicu-dev 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for bison... no configure: error: bison not found # 提示,未找到bison 安装bison包:
apt install -y bison 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for flex... no configure: error: flex not found # 提示,未找到flex 安装flex包:
apt install -y flex 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for library containing readline... no configure: error: readline library not found # 提示,未找到readline库 If you have readline already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-readline to disable readline support. 安装libreadline-dev包:
apt install -y libreadline-dev 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: zlib library not found # 提示,为找到zlib库 If you have zlib already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-zlib to disable zlib support. 安装zlib1g-dev包:
apt install -y zlib1g-dev 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for CRYPTO_new_ex_data in -lcrypto... no configure: error: library 'crypto' is required for OpenSSL # 提示,需要库 'crypto' 来支持 OpenSSL 安装libssl-dev包:
apt install -y libssl-dev 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for xmlSaveToBuffer in -lxml2... no configure: error: library 'xml2' (version >= 2.6.23) is required for XML support # 提示,需要库 'xml2'(版本 >= 2.6.23)以支持 XML 安装libxml2-dev包:
apt install -y libxml2-dev 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: header file <systemd/sd-daemon.h> is required for systemd support # 提示,需要头文件 <systemd/sd-daemon.h> 以支持 systemd 安装libsystemd-dev包:
apt install -y libsystemd-dev 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd 执行make:
apt install -y make # 默认 make 不包括文档和其它模块,$(nproc)表示当产主机的CPU核心 make -j $(nproc) world ... make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/test/isolation' make -C test/perl all make[2]: Entering directory '/usr/local/src/postgresql-17.6/src/test/perl' make[2]: Nothing to be done for 'all'. make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/test/perl' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/src' 执行make install:
# 默认 make install 不包括安装文档 make install-world ... ERROR: `xmllint' is missing on your system. *** make[3]: *** [Makefile:72: postgres-full.xml] Error 1 make[3]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src/sgml' make[2]: *** [Makefile:8: install] Error 2 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src' make[1]: *** [Makefile:16: install] Error 2 make[1]: Leaving directory '/usr/local/src/postgresql-17.6/doc' make: *** [GNUmakefile:32: install-world-doc-recurse] Error 2 apt install -y docbook-xml docbook-xsl libxml2-utils xsltproc fop 重新执行make install:
make install-world ... ERROR: `xmllint' is missing on your system. *** make[3]: *** [Makefile:72: postgres-full.xml] Error 1 make[3]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src/sgml' make[2]: *** [Makefile:8: install] Error 2 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src' make[1]: *** [Makefile:16: install] Error 2 make[1]: Leaving directory '/usr/local/src/postgresql-17.6/doc' make: *** [GNUmakefile:32: install-world-doc-recurse] Error 2 重新执行configure:
# 再次执行make之前先清理之前的操作 make clean ./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd 重新执行make:
make -j $(nproc) world 重新执行make install:
make install-world 。。。 /usr/bin/mkdir -p '/apps/pgsql/lib' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/install -c -m 755 pgxml.so '/apps/pgsql/lib/pgxml.so' /usr/bin/install -c -m 644 ./xml2.control '/apps/pgsql/share/extension/' /usr/bin/install -c -m 644 ./xml2--1.1.sql ./xml2--1.0--1.1.sql '/apps/pgsql/share/extension/' make[2]: Leaving directory '/usr/local/src/postgresql-17.6/contrib/xml2' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/contrib' 总结编译过程:
# 安装依赖包 apt update apt install -y gcc pkg-config libicu-dev bison flex libreadline-dev zlib1g-dev libssl-dev libxml2-dev libsystemd-dev make docbook-xml docbook-xsl libxml2-utils xsltproc fop # 进入PostgreSQL包解压的目录: cd postgresql-17.6 # 执行configure ./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd # 执行make make -j $(nproc) world # 执行make install make install-world 2.3.2.9 Ubuntu Server 18.04 LTS
进入PostgreSQL包解压的目录:
cd postgresql-17.6 执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: no acceptable C compiler found in $PATH # 提示,在$PATH中找不到可接受的C编译器,需要安装gcc See `config.log' for more details 安装gcc包:
apt install -y gcc 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for pkg-config... no # 没有检测到pkg-config,要安装pkg-config,否则还会出现报错 checking whether to build with ICU support... yes checking for icu-uc icu-i18n... no configure: error: ICU library not found # 提示,未找到 ICU 库 If you have ICU already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-icu to disable ICU support. 安装pkg-config和libicu-dev包:
apt install -y pkg-config libicu-dev 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for bison... no configure: error: bison not found # 提示,未找到bison 安装bison包:
apt install -y bison 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for flex... no configure: error: flex not found # 提示,未找到flex 安装flex包:
apt install -y flex 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for library containing readline... no configure: error: readline library not found # 提示,未找到readline库 If you have readline already installed, see config.log for details on the failure. It is possible the compiler isn't looking in the proper directory. Use --without-readline to disable readline support. 安装libreadline-dev包:
apt install -y libreadline-dev 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for CRYPTO_new_ex_data in -lcrypto... no configure: error: library 'crypto' is required for OpenSSL # 提示,需要库 'crypto' 来支持 OpenSSL 安装libssl-dev包:
apt install -y libssl-dev 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... checking for xmlSaveToBuffer in -lxml2... no configure: error: library 'xml2' (version >= 2.6.23) is required for XML support # 提示,需要库 'xml2'(版本 >= 2.6.23)以支持 XML 安装libxml2-dev包:
apt install -y libxml2-dev 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd ... configure: error: header file <systemd/sd-daemon.h> is required for systemd support # 提示,需要头文件 <systemd/sd-daemon.h> 以支持 systemd 安装libsystemd-dev包:
apt install -y libsystemd-dev 继续执行configure:
./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd 执行make:
apt install -y make # 默认 make 不包括文档和其它模块,$(nproc)表示当产主机的CPU核心 make -j $(nproc) world ... make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/test/isolation' make -C test/perl all make[2]: Entering directory '/usr/local/src/postgresql-17.6/src/test/perl' make[2]: Nothing to be done for 'all'. make[2]: Leaving directory '/usr/local/src/postgresql-17.6/src/test/perl' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/src' 执行make install:
# 默认 make install 不包括安装文档 make install-world ... ERROR: `xmllint' is missing on your system. *** make[3]: *** [Makefile:72: postgres-full.xml] Error 1 make[3]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src/sgml' make[2]: *** [Makefile:8: install] Error 2 make[2]: Leaving directory '/usr/local/src/postgresql-17.6/doc/src' make[1]: *** [Makefile:16: install] Error 2 make[1]: Leaving directory '/usr/local/src/postgresql-17.6/doc' make: *** [GNUmakefile:32: install-world-doc-recurse] Error 2 apt install -y docbook-xml docbook-xsl libxml2-utils xsltproc fop 重新执行configure:
# 再次执行make之前先清理之前的操作 make clean ./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd 重新执行make:
make -j $(nproc) world 重新执行make install:
make install-world 。。。 /usr/bin/mkdir -p '/apps/pgsql/lib' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/mkdir -p '/apps/pgsql/share/extension' /usr/bin/install -c -m 755 pgxml.so '/apps/pgsql/lib/pgxml.so' /usr/bin/install -c -m 644 ./xml2.control '/apps/pgsql/share/extension/' /usr/bin/install -c -m 644 ./xml2--1.1.sql ./xml2--1.0--1.1.sql '/apps/pgsql/share/extension/' make[2]: Leaving directory '/usr/local/src/postgresql-17.6/contrib/xml2' make[1]: Leaving directory '/usr/local/src/postgresql-17.6/contrib' 总结编译过程:
# 安装依赖包 apt update apt install -y gcc pkg-config libicu-dev bison flex libreadline-dev libssl-dev libxml2-dev libsystemd-dev make docbook-xml docbook-xsl libxml2-utils xsltproc fop # 进入PostgreSQL包解压的目录: cd postgresql-17.6 # 执行configure ./configure --prefix=/apps/pgsql --with-openssl --with-libxml --with-systemd # 执行make make -j $(nproc) world # 执行make install make install-world 2.3.3 创建数据库用户和组
PostgreSQL默认不支持 以root 身份启动服务,虽然也可修改源码实现root启动,但基于安全考虑不建议,因此必须创建一个用于启动PostgrepSQL的普通用户
# 创建数据库用户和组,注意此用户需要可以交互登录 # Rocky、Almalinux、CentOS、openEuler、AnolisOS、OpenCloudOS、 Kylin Server、UOS Server、Ubuntu、Debian useradd -s /bin/bash -m -d /home/postgres postgres # openSUSE groupadd postgres useradd -s /bin/bash -m -d /home/postgres -g postgres postgres # 修改postgres密码 echo postgres:123456|chpasswd 2.3.4 创建数据目录并授权
mkdir -p /data/pgsql/ chown -R postgres:postgres /data/pgsql/ 2.3.5 设置环境变量
cat > /etc/profile.d/pgsql.sh <<EOF export PGHOME=/apps/pgsql export PATH=\$PGHOME/bin/:\$PATH export PGDATA=/data/pgsql export PGUSER=postgres export MANPATH=\$PGHOME/share/man EOF . /etc/profile.d/pgsql.sh 2.3.6 初始化数据库
[root@rocky10 postgresql-17.6]# su - postgres -c '/apps/pgsql/bin/initdb -D /data/pgsql' The files belonging to this database system will be owned by user "postgres". This user must also own the server process. The database cluster will be initialized with locale "en_US.UTF-8". The default database encoding has accordingly been set to "UTF8". The default text search configuration will be set to "english". Data page checksums are disabled. fixing permissions on existing directory /data/pgsql ... ok creating subdirectories ... ok selecting dynamic shared memory implementation ... posix selecting default "max_connections" ... 100 selecting default "shared_buffers" ... 128MB selecting default time zone ... Asia/Shanghai creating configuration files ... ok running bootstrap script ... ok performing post-bootstrap initialization ... ok syncing data to disk ... ok initdb: warning: enabling "trust" authentication for local connections initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb. Success. You can now start the database server using: pg_ctl -D /data/pgsql -l logfile start 2.3.7 准备启动脚本并启动服务
# Rocky、Almalinux、CentOS、openEuler、AnolisOS、OpenCloudOS、 Kylin Server、UOS Server、openSUSE cat > /usr/lib/systemd/system/postgresql.service <<EOF [Unit] Description=PostgreSQL database server After=network.target [Service] User=postgres Group=postgres ExecStart=/apps/pgsql/bin/postgres -D /data/pgsql ExecReload=/bin/kill -HUP \$MAINPID [Install] WantedBy=multi-user.target EOF # Ubuntu和Debian cat > /lib/systemd/system/postgresql.service <<EOF [Unit] Description=PostgreSQL database server After=network.target [Service] User=postgres Group=postgres ExecStart=/apps/pgsql/bin/postgres -D /data/pgsql ExecReload=/bin/kill -HUP [Install] WantedBy=multi-user.target EOF systemctl daemon-reload && systemctl enable --now postgresql 2.3.8 登录测试
[root@rocky10 postgresql-17.6]# sudo -u postgres /apps/pgsql/bin/psql -c "SELECT version();" version ------------------------------------------------------------------------------------------------------- PostgreSQL 17.6 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, 64-bit (1 row) [root@rocky10 postgresql-17.6]# su - postgres Last login: Mon Sep 8 16:47:39 CST 2025 on pts/0 [postgres@rocky10 ~]$ psql psql (17.6) Type "help" for help. postgres=# help You are using psql, the command-line interface to PostgreSQL. Type: \copyright for distribution terms \h for help with SQL commands \? for help with psql commands \g or terminate with semicolon to execute query \q to quit postgres=# \q 2.3.9 一键安装PostgreSQL源码编译的脚本
Shell脚本源码地址:
Gitee:https://gitee.com/raymond9/shell
Github:https://github.com/raymond999999/shell
可以去上面的Gitee或Github代码仓库拉取脚本。
[root@rocky10 ~]# cat install_postgresql_source.sh #!/bin/bash # #********************************************************************************** #Author: Raymond #QQ: 88563128 #MP: Raymond运维 #Date: 2025-09-22 #FileName: install_postgresql_source.sh #URL: https://wx.zsxq.com/group/15555885545422 #Description: The postgresql source script install supports # “Rocky Linux 8, 9 and 10, AlmaLinux 8, 9 and 10, CentOS 7, # CentOS Stream 8, 9 and 10, openEuler 22.03 and 24.03 LTS, # AnolisOS 8 and 23, OpenCloudOS 8 and 9, Kylin Server v10 and v11, # UOS Server v20, Ubuntu Server 18.04, 20.04, 22.04 and 24.04 LTS, # Debian 11 , 12 and 13, openSUSE Leap 15“ operating systems. #Copyright (C): 2025 All rights reserved #********************************************************************************** COLOR="echo -e \\033[01;31m" END='\033[0m' os(){ . /etc/os-release MAIN_NAME=`sed -rn '/^NAME=/s@.*="([[:alpha:]]+).*"$@\1@p' /etc/os-release` if [ ${MAIN_NAME} == "Kylin" ];then MAIN_VERSION_ID=`sed -rn '/^VERSION_ID=/s@.*="([[:alpha:]]+)(.*)"$@\2@p' /etc/os-release` else MAIN_VERSION_ID=`sed -rn '/^VERSION_ID=/s@.*="?([0-9]+)\.?.*"?@\1@p' /etc/os-release` fi if [ ${MAIN_NAME} == "Ubuntu" -o ${MAIN_NAME} == "Debian" ];then FULL_NAME="${PRETTY_NAME}" elif [ ${MAIN_NAME} == "UOS" ];then FULL_NAME="${NAME}" else FULL_NAME="${NAME} ${VERSION_ID}" fi } os SRC_DIR=/usr/local/src INSTALL_DIR=/apps/pgsql DATA_DIR=/data/pgsql DB_USER=postgres POSTGRESQL_VERSION=17.6 POSTGRESQL_URL="https://ftp.postgresql.org/pub/source/v${POSTGRESQL_VERSION}/" POSTGRESQL_FILE="postgresql-${POSTGRESQL_VERSION}.tar.gz" DB_USER_PASSWORD=123456 check_file(){ cd ${SRC_DIR} if [ ${MAIN_NAME} == "Rocky" -o ${MAIN_NAME} == "AlmaLinux" -o ${MAIN_NAME} == "CentOS" -o ${MAIN_NAME} == "Anolis" -o ${MAIN_NAME} == "OpenCloudOS" -o ${MAIN_NAME} == "Kylin" ];then rpm -q wget &> /dev/null || { ${COLOR}"安装wget工具,请稍等......"${END};yum -y install wget &> /dev/null; } fi if [ ! -e ${POSTGRESQL_FILE} ];then ${COLOR}"缺少${POSTGRESQL_FILE}文件!"${END} ${COLOR}'开始下载PostgreSQL源码包......'${END} wget ${POSTGRESQL_URL}${POSTGRESQL_FILE} || { ${COLOR}"PostgreSQL源码包下载失败!"${END}; exit; } else ${COLOR}"${POSTGRESQL_FILE}文件已准备好!"${END} fi } install_postgresql(){ [ -d ${INSTALL_DIR} ] && { ${COLOR}"PostgreSQL数据库已存在,安装失败!"${END};exit; } ${COLOR}"开始安装PostgreSQL数据库......"${END} ${COLOR}'开始安装PostgreSQL依赖包,请稍等......'${END} if [ ${MAIN_NAME} == "Rocky" -o ${MAIN_NAME} == "AlmaLinux" -o ${MAIN_NAME} == "CentOS" -o ${MAIN_NAME} == "OpenCloudOS" ];then yum install -y gcc libicu-devel bison flex perl readline-devel zlib-devel openssl-devel libxml2-devel systemd-devel docbook-dtds docbook-style-xsl libxslt &> /dev/null fi if [ ${MAIN_NAME} == "openEuler" ];then yum install -y gcc libicu-devel bison flex readline-devel zlib-devel openssl-devel libxml2-devel systemd-devel docbook-dtds docbook-style-xsl libxslt &> /dev/null fi if [ ${MAIN_NAME} == "Anolis" ];then if [ ${MAIN_VERSION_ID} == 8 ];then yum install -y gcc libicu-devel bison flex readline-devel zlib-devel openssl-devel libxml2-devel systemd-devel make docbook-dtds docbook-style-xsl libxslt &> /dev/null else yum install -y gcc libicu-devel bison flex readline-devel zlib-devel openssl-devel libxml2-devel systemd-devel perl-FindBin perl-core docbook-dtds docbook-style-xsl libxslt &> /dev/null fi fi if [ ${MAIN_NAME} == "Kylin" ];then yum install -y gcc libicu-devel bison flex perl readline-devel zlib-devel openssl-devel libxml2-devel systemd-devel docbook-dtds docbook-style-xsl libxslt &> /dev/null fi if [ ${MAIN_NAME} == "UOS" ];then if [ ${MAIN_VERSION_ID} == 20 ];then yum install -y libicu-devel bison flex perl readline-devel systemd-devel docbook-dtds docbook-style-xsl libxslt &> /dev/null fi fi if [ ${MAIN_NAME} == "openSUSE" ];then if [ ${MAIN_VERSION_ID} == 15 ];then zypper install -y gcc libicu-devel bison flex readline-devel zlib-devel openssl-devel libxml2-devel systemd-devel make docbook-xsl-stylesheets &> /dev/null fi fi if [ ${MAIN_NAME} == "Ubuntu" ];then if [ ${MAIN_VERSION_ID} == 18 ];then apt update && apt install -y gcc pkg-config libicu-dev bison flex libreadline-dev libssl-dev libxml2-dev libsystemd-dev make docbook-xml docbook-xsl libxml2-utils xsltproc fop else apt update && apt install -y gcc pkg-config libicu-dev bison flex libreadline-dev zlib1g-dev libssl-dev libxml2-dev libsystemd-dev make docbook-xml docbook-xsl libxml2-utils xsltproc fop fi fi if [ ${MAIN_NAME} == 'Debian' ];then apt update && apt install -y gcc pkg-config libicu-dev bison flex libreadline-dev zlib1g-dev libssl-dev libxml2-dev libsystemd-dev make docbook-xml docbook-xsl libxml2-utils xsltproc fop fi ${COLOR}'开始编译安装PostgreSQL,请稍等......'${END} cd ${SRC_DIR} if [ ${MAIN_NAME} == "openEuler" ];then if [ ${MAIN_VERSION_ID} == 22 -o ${MAIN_VERSION_ID} == 24 ];then yum install -y tar &> /dev/null fi fi if [ ${MAIN_NAME} == "Anolis" ];then if [ ${MAIN_VERSION_ID} == 23 ];then yum install -y tar &> /dev/null fi fi if [ ${MAIN_NAME} == "OpenCloudOS" ];then if [ ${MAIN_VERSION_ID} == 9 ];then yum install -y tar &> /dev/null fi fi tar xf ${POSTGRESQL_FILE} POSTGRESQL_DIR=`echo ${POSTGRESQL_FILE}| sed -nr 's/^(.*[0-9]).*/\1/p'` cd ${POSTGRESQL_DIR} ./configure --prefix=${INSTALL_DIR} --with-openssl --with-libxml --with-systemd make -j $(nproc) world make install-world [ $? -eq 0 ] && ${COLOR}"PostgreSQL编译安装成功!"${END} || { ${COLOR}"PostgreSQL编译安装失败,退出!"${END};exit; } if [ ${MAIN_NAME} == "openSUSE" ];then id ${DB_USER} &> /dev/null || { groupadd ${DB_USER} && useradd -s /bin/bash -m -d /home/${DB_USER} -g ${DB_USER} ${DB_USER}; ${COLOR}"成功创建${DB_USER}用户!"${END}; } else id ${DB_USER} &> /dev/null || { useradd -s /bin/bash -m -d /home/${DB_USER} ${DB_USER} ; ${COLOR}"成功创建${DB_USER}用户!"${END}; } fi echo ${DB_USER}:${DB_USER_PASSWORD}|chpasswd [ -d ${DATA_DIR} ] || mkdir -p ${DATA_DIR}/ chown -R ${DB_USER}:${DB_USER} ${DATA_DIR}/ cat > /etc/profile.d/pgsql.sh <<EOF export PGHOME=${INSTALL_DIR} export PATH=${INSTALL_DIR}/bin/:\$PATH export PGDATA=${DATA_DIR} export PGUSER=${DB_USER} export MANPATH=${INSTALL_DIR}/share/man alias pgstart="pg_ctl -D ${DATA_DIR} start" alias pgstop="pg_ctl -D ${DATA_DIR} stop" alias pgrestart="pg_ctl -D ${DATA_DIR} restart" alias pgstatus="pg_ctl -D ${DATA_DIR} status" EOF su - ${DB_USER} -c "${INSTALL_DIR}/bin/initdb -D ${DATA_DIR}" if [ ${MAIN_NAME} == "Ubuntu" -o ${MAIN_NAME} == "Debian" ];then cat > /lib/systemd/system/postgresql.service <<EOF [Unit] Description=PostgreSQL database server After=network.target [Service] User=${DB_USER} Group=${DB_USER} ExecStart=${INSTALL_DIR}/bin/postgres -D ${DATA_DIR} ExecReload=/bin/kill -HUP \$MAINPID [Install] WantedBy=multi-user.target EOF else cat > /usr/lib/systemd/system/postgresql.service <<EOF [Unit] Description=PostgreSQL database server After=network.target [Service] User=${DB_USER} Group=${DB_USER} ExecStart=${INSTALL_DIR}/bin/postgres -D ${DATA_DIR} ExecReload=/bin/kill -HUP \$MAINPID [Install] WantedBy=multi-user.target EOF fi systemctl daemon-reload && systemctl enable --now postgresql &> /dev/null [ $? -ne 0 ] && { ${COLOR}"数据库启动失败,退出!"${END};exit; } ${COLOR}"${FULL_NAME}操作系统,PostgreSQL数据库安装完成!"${END} } main(){ check_file install_postgresql } if [ ${MAIN_NAME} == "Rocky" ];then if [ ${MAIN_VERSION_ID} == 8 -o ${MAIN_VERSION_ID} == 9 -o ${MAIN_VERSION_ID} == 10 ];then main fi elif [ ${MAIN_NAME} == "AlmaLinux" ];then if [ ${MAIN_VERSION_ID} == 8 -o ${MAIN_VERSION_ID} == 9 -o ${MAIN_VERSION_ID} == 10 ];then main fi elif [ ${MAIN_NAME} == "CentOS" ];then if [ ${MAIN_VERSION_ID} == 7 -o ${MAIN_VERSION_ID} == 8 -o ${MAIN_VERSION_ID} == 9 -o ${MAIN_VERSION_ID} == 10 ];then main fi elif [ ${MAIN_NAME} == "openEuler" ];then if [ ${MAIN_VERSION_ID} == 22 -o ${MAIN_VERSION_ID} == 24 ];then main fi elif [ ${MAIN_NAME} == "Anolis" ];then if [ ${MAIN_VERSION_ID} == 8 -o ${MAIN_VERSION_ID} == 23 ];then main fi elif [ ${MAIN_NAME} == 'OpenCloudOS' ];then if [ ${MAIN_VERSION_ID} == 8 -o ${MAIN_VERSION_ID} == 9 ];then main fi elif [ ${MAIN_NAME} == "Kylin" ];then if [ ${MAIN_VERSION_ID} == 10 ];then main fi elif [ ${MAIN_NAME} == "UOS" ];then if [ ${MAIN_VERSION_ID} == 20 ];then main fi elif [ ${MAIN_NAME} == "openSUSE" ];then if [ ${MAIN_VERSION_ID} == 15 ];then main fi elif [ ${MAIN_NAME} == "Ubuntu" ];then if [ ${MAIN_VERSION_ID} == 18 -o ${MAIN_VERSION_ID} == 20 -o ${MAIN_VERSION_ID} == 22 -o ${MAIN_VERSION_ID} == 24 ];then main fi elif [ ${MAIN_NAME} == 'Debian' ];then if [ ${MAIN_VERSION_ID} == 11 -o ${MAIN_VERSION_ID} == 12 -o ${MAIN_VERSION_ID} == 13 ];then main fi else ${COLOR}"此脚本不支持${FULL_NAME}操作系统!"${END} fi