前些年写了一个PostgreSQL自动化安装的shell脚本,这几年一直在用,中间有微调过但都可以正常一键安装,今天尝试安装一个最新版的PostgreSQL 17.6(Aug. 11, 2025发布的),发现编译过程中死活过不去,遇到如下几个错误
1,ERROR: `xmllint' is missing on your system.,安装libxml2-utils依赖包后没有出现了
sudo apt update
sudo apt install libxml2-utils
2,postgres.sgml:24: element book: validity error : No declaration for attribute id of element book
是在 PostgreSQL 源码编译文档(make world 会编译 doc) 时出现的 XML/SGML 校验错误。请教大佬后说是“从17开始,与源码包同时提供了doc包”。
默认(make world)会编译docs,但是编译docs会有一系列的依赖,经过安装如下依赖包后依旧无解。。。。。。
sudo apt update
sudo apt install docbook docbook-dsssl docbook-xml docbook-xsl
sudo apt install xsltproc fop
3,移除docs的编译
参考:https://www.postgresql.org/docs/current/install-make.html#CONFIGURE-OPTIONS
翻阅了一下官方文档,提示说If you want to build everything that can be built, including the additional modules (contrib), but without the documentation, type instead:If you built the world without the documentation above, type instead:因此编译时用make world-bin替代原来的make world,安装时用make install-world-bin替代原来的make install-world,来绕过docs的编译,随后安装成功。
附,PostgreSQL 17 自动化安装代码
[code]#!/bin/bash# 1,PostgreSQL源码包名称(假设已下载并位于当前目录的同级目录中)POSTGRESQL_SRC="postgresql-17.6.tar.gz" # 替换XX.X为你的PostgreSQL版本POSTGRESQL_DIR="postgresql-17.6" # 解压后的目录名,同样替换XX.X# 2,安装目录INSTALL_DIR="/usr/local/pgsql17/server"# 3,端口号PORT=9700# 4,初始密码(通过参数传入,默认为空)INIT_PASSWORD="A-Strong-Password"if [ $# -gt 0 ]; then INIT_PASSWORD="$1"fi# 实例目录INSTANCE_DATA_DIR="/usr/local/pgsql17/pg${PORT}/data"INSTANCE_LOG_DIR="/usr/local/pgsql17/pg${PORT}/log"# 创建postgres用户(如果尚未存在)if ! id postgres &>/dev/null; then echo "Creating postgres user..." sudo groupadd postgres sudo useradd -m -g postgres postgres -s /bin/bash echo " ostgres user created successfully."else echo " ostgres user already exists."fi# 检查目录是否存在if [ ! -d "$INSTALL_DIR" ]; then echo "dir '$INSTALL_DIR' not existing,creating..." mkdir -p "$INSTALL_DIR" echo "dir '$INSTALL_DIR' created。"else echo "dir '$INSTALL_DIR' existing。"fi# 检查实例目录是否存在if [ ! -d "$INSTANCE_DATA_DIR" ]; then echo "dir '$INSTANCE_DATA_DIR' not existing,creating..." mkdir -p "$INSTANCE_DATA_DIR" mkdir -p "$INSTANCE_LOG_DIR" echo "dir '$INSTANCE_DATA_DIR' created。"else echo "dir '$INSTANCE_DATA_DIR' existing。"fi# 安装编译依赖项echo "############################Installing build dependencies... "sudo apt update -y > /dev/null 2>&1sudo apt install -y systemtap-sdt-dev libicu-dev libreadline-dev zlib1g-dev libssl-dev libpam0g-dev libxml2-dev libxslt1-dev libldap2-dev libsystemd-dev tcl-dev libpython3-dev libperl-dev > /dev/null 2>&1echo "############################Done."# 解压源码包echo "############################Extracting PostgreSQL source code... "tar -xzvf "$POSTGRESQL_SRC" > /dev/null 2>&1echo "############################Done."# 进入解压后的目录cd "$POSTGRESQL_DIR"# 配置PostgreSQL(这里使用默认配置,但可以添加--prefix等选项)echo "############################Configuring PostgreSQL... "#make clean./configure --prefix="$INSTALL_DIR" --with-openssl > /dev/null 2>&1echo "############################Done."# 编译PostgreSQLecho -n "############################Compiling PostgreSQL (this may take a while)... "# pg 17之前,用make world -j$(nproc) > /dev/null 2>&1make world-bin -j$(nproc) > /dev/null 2>&1echo "############################Done."# 安装PostgreSQLecho "############################Installing PostgreSQL... "# pg 17之前,用make install-world > /dev/null 2>&1sudo make install-world-bin > /dev/null 2>&1echo "############################Done."# 初始化数据库(使用postgres用户)echo "############################Initializing PostgreSQL database..."chown -R postgres:postgres $INSTALL_DIRchmod 700 -R $INSTALL_DIRchown -R postgres:postgres $INSTANCE_DATA_DIRchmod 700 -R $INSTANCE_DATA_DIRchown -R postgres:postgres $INSTANCE_LOG_DIRchmod 700 -R $INSTANCE_LOG_DIRsudo -u postgres $INSTALL_DIR/bin/initdb -D $INSTANCE_DATA_DIR# 1. 创建systemd服务(使用指定模板)echo "############################Creating systemd service..."cat |