本文简要介绍如何在 FreeBSD 上搭建 PostgreSQL 开发环境,以及如何编译 PostgreSQL 数据库。

安装依赖

首先安装依赖,使用下面的命令我们可以安装本次实验所需的依赖,如果您需要添加额外的编译选项,您可能还需要安装其他依赖。

# pkg install -y gcc11-11.3.0_7
# pkg install -y gmake-4.3_2
# pkg install -y flex-2.6.4_2
# pkg install -y bison-3.8.2,1
# pkg install -y pkgconf
# pkg install -y gettext-tools-0.21.1

# pkg install -y icu-72.1,1               # --with-icu
# pkg install -y libxml2-2.10.3_1         # --with-libxml
# pkg install -y libxslt                  # --with-libxslt
# pkg install -y openldap26-client        # --with-ldap
# pkg install -y openssl-devel-3.0.5      # --with-openssl

# pkg install -y p5-IPC-Run-20220807.0    # --enable-tap-tests

编译

安装所需依赖之后,我们可以使用下面的命令来编译 PostgreSQL 数据库。根据个人的需求,您可能有不同的编译选项(可能需要安装对应的依赖),本文给出一个简单的编译示例。

#!/usr/bin/env bash

rm -rf $(ls | grep -v -E ".*sh$")
../configure --prefix=$PWD/hhdb \
  --enable-cassert \
  --enable-debug \
  --enable-depend \
  --enable-nls \
  --enable-rpath \
  --enable-tap-tests \
  --enable-thread-safety \
  --with-gssapi \
  --with-icu \
  --with-ldap \
  --with-libxml \
  --with-libxslt \
  --with-openssl \
  --with-libedit-preferred \
  --with-pam \
  --with-perl \
  --with-python \
  --with-system-tzdata=/usr/share/zoneinfo \
  --with-uuid=bsd \
  CFLAGS="-ggdb -O0 -ftree-vectorize -pipe -fexceptions -Wl,-rpath,$PWD/hhdb/lib -I/usr/local/include" && \
gmake -j 2 -s && gmake install -s && \
cd contrib && gmake -j 2 -s && gmake install -s && cd -

接着运行 make check-world 跑回归测试。

运行时环境

编译之后,运行时需要安装的依赖如下所示:

# pkg install -y icu-72.1,1               # --with-icu
# pkg install -y libxml2-2.10.3_1         # --with-libxml
# pkg install -y libxslt                  # --with-libxslt
# pkg install -y openldap26-client        # --with-ldap
# pkg install -y openssl-devel-3.0.5      # --with-openssl