1.下载PostgreSQL源码
https://www.postgresql.org/ftp/source/v12.8/
2.安装依赖包:
yum groupinstall "Development tools"
yum install -y bison flex readline-devel zlib-devel
3.安装PostgreSQL
1.解压安装包
tar -xvf postgresql-12.8.tar.gz
cd postgresql-12.8/
2.配置编译:
./configure --prefix=/opt/pg12/ --with-pgport=1921
3.编译
gmake world
PostgreSQL, contrib, and documentation successfully made. Ready to install. <----出现此行,表示编译成功。
4.安装
gmake install-world
PostgreSQL, contrib, and documentation installation complete. <----出现此行,表示安装成功。
5.查看安装的版本
/opt/pg12/bin/postgres --version
postgres (PostgreSQL) 12.8
6.设置软链接,避免升级后调整大量脚本
ln -s /opt/pg12 /opt/pgsql
lrwxrwxrwx 1 root root 9 Oct 7 05:53 pgsql -> /opt/pg12
7.将/opt/pgsql/bin路径加入到用户PATH
PATH=$PATH:$HOME/bin:/opt/pgsql/bin
生效:
source .bash_profile
验证有效性:
[root@pg02 ~]# psql
psql: error: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.1921"?
至此,PostgreSQL12.8以源码方式安装完成。
参考官方文档:




