操作系统:ubuntu 22.04.3 TLS
编译器:clang 或者 gcc,尽量使用最新版的编译器。
一、安装前准备:
1.必要的依赖包
apt install bison flex libssl-dev
2.cmake
可以用apt安装,或者去官网下载最新版本自行编译安装。
wget https://github.com/Kitware/CMake/releases/download/v3.27.6/cmake-3.27.6.tar.gz tar zxvf cmake-3.27.6.tar.gz cd cmake-3.27.6 ./configure makemake install
3.llvm
如果想要使用jit则需要安装llvm和clang,这里以15.0.7为例,说明自行编译的方法。
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/llvm-project-15.0.7.src.tar.xz tar Jxvf llvm-project-15.0.7.src.tar.xz mkdir-p llvm-project-15.0.7.src/build cd llvm-project-15.0.7.src/build cmake -DCMAKE_BUILD_TYPE=Release \ -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" \ -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \ -DLLVM_TARGETS_TO_BUILD=Native \ -DCMAKE_INSTALL_PREFIX="/usr/local" \ ../llvm make-j10#这里根据自己的cpu个数来决定cmake -P cmake_install.cmake
二、编译安装PostgreSQL
wget https://ftp.postgresql.org/pub/source/v16.0/postgresql-16.0.tar.gz tar zxvf postgresql-16.0.tar.gz cd postgresql-16.0 #这里使用clang编译CC=/usr/local/llvm/bin/clang CFLAGS="-O3 -fstrict-enums -fno-signed-zeros" \ CLANG=/usr/local/llvm/bin/clang LLVM_CONFIG=/usr/local/llvm/bin/llvm-config \ ./configure --prefix=/usr/local/pgsql16 --with-llvm--with-openssl--without-icu#如果不想使用clang编译CFLAGS="-O3" \ LLVM_CONFIG=/usr/local/llvm/bin/llvm-config \ ./configure --prefix=/usr/local/pgsql16 --with-llvm--with-openssl--without-icu#请仔细查看configure的输出信息,如果发现有依赖包未安装,请自行用apt安装后重新执行configuremake world -j10make install-world
三、llvm加载
jit可提升某些sql的性能,如果需要使用,可在initdb完成后,修改postgresql.conf,打开git选项
jit_provider ='llvmjit'# JIT library to usejit_above_cost =100000# perform JIT compilation if available# and query more expensive than this;# -1 disablesjit_inline_above_cost =500000# inline small functions if query is# more expensive than this; -1 disablesjit_optimize_above_cost =500000# use expensive JIT optimizations if# query is more expensive than this;# -1 disablesjit = on # allow JIT compilation