alpine 编译安装postgresql16.4

时间:2025-04-09 14:47:48
解压缩postgresql16.4的源码压缩文件
创建 postgres用户及组
用addgroup 和adduser
addgroup -g 1001 postgres
adduser -G postgres postgres
拷贝至
mv postgresql-16.4/* /home/postgres/postgresql16.4/
变更目录所有
chown -R postgres:postgres   /home/postgres/postgresql16.4
默认编译至
/usr/local/pgsql 目录
创建此目录
mkdir -p /usr/local/pgsql
变换用户
chown -R postgres:postgres /usr/local/pgsql
切换用户
su - postgres
进入目录
./configure
提示
configure: error: ICU library not found
If you have ICU already installed, see for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-icu to disable ICU support.
安装icu包
apk add icu-dev
再次配置
提示
configure: error: readline library not found
安装readline对应包
apk add readline-dev
提示
configure: error: zlib library not found
安装
apk add zlib-dev
再次
./configure
编译
make all 
安装
make install
安装完成。
编辑环境变量
编写
vim
填入一下内容,注意alpine需要path加入 /bin目录,否则会导致ls不能用。

export PGPORT=5432

export PGDATA=/home/postgres/data

export LANG=en_US.utf8

export PGHOME=/usr/local/pgsql

export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH

export PATH=$PGHOME/bin:/usr/bin:/usr/local/sbin:/bin:

export MANPATH=$PGHOME/share/man:/share/man:

应用环境更改
source
初始化数据库

initdb -D $PGDATA --encoding=UTF8 --locale=en_US.UTF8 -U postgres

 提示警告,没关系。

 no usable system locales were found

更改  和 配置连接即可。
pg_ctl start