PostgreSQL 手动编译源码安装
PostgreSQL 数据库提供预编译rpm/deb 包以及源码包 2种安装方式,不像mysql 提供了通用linux 平台二进制自定义压缩包,由于rpm、deb 等安装包不能自定义安装路径适合测试环境部署,生产环境建议选择源码包手动编译二进制文件安装方式,下面介绍手动编译安装方式:
1、PostgreSQL 官网下载 源码压缩包,这里选择下载最新13.4稳定版:
官网下载地址 https://www.postgresql.org/ftp/source/v13.4/

2、Linux 服务器提前配置好yum 源,操作系统选择readhat/oracle/rocky/suse linux 均可,使用yum 安装好编译器、依赖库:
yum install cmake gcc gcc-c++ perl readline-devel zlib zlib-devel tcl openssl ncurses-devel openldap


3、服务器上建立PostgreSQL 安装目录、账号以及配置好环境变量:


4、上传源码包,解压缩、编译安装:

tar -xzf postgresql-13.4.tar.gz
cd postgresql-13.4
./configure --prefix=/pgsql/13.4/

通过 加上--help 选型可以查看不同的编译选项,加上对应选项可以开启或者关闭对应功能支持



编译安装,依据cpu核心数,可以指定多个并行度加快编译速度:
make -j 4 && make install


如是想将contrib下的扩展一同安装,使用make world && make install-world 命令编译安装
清理编译时产生的临时文件
make clean

进入安装目录,查看生成的文件
cd /pgsql/13.4/bin/


5、初始化PostgreSQL,完成安装:
su - postgres
pg_ctl initdb


6、将postgresql添加至系统自启动服务:
cd /home/postgres/postgresql-13.4/contrib/start-scripts/
cp linux /etc/init.d/postgresql
cd cd /etc/init.d/
chmod a+x postgresql
vim /etc/init.d/postgresql --确保prefix、PGDATA 变量指向postgresql 实际安装路径
# Installation prefix
prefix=/pgsql/13.4
# Data directory
PGDATA="/pgsql/13.4/data"
# Who to run the postmaster as, usually "postgres". (NOT "root")
PGUSER=postgres
chkconfig postgresql on --增加开机自启动服务
本文来自博客园,作者:踏雪无痕2017,转载请注明原文链接:https://www.cnblogs.com/oradba/p/15329674.html

浙公网安备 33010602011771号