1、解压postgres15.1
tar -zxvf postgresql-15.1.tar.gz
cd postgresql-15.1/
2、安装依赖
yum install -y bison
yum install -y flex
yum install -y readline-devel
yum install -y zlib-devel
yum install -y gcc
yum install -y libxml2
yum install -y libxml2-devel
yum install -y lz4
yum install -y systemtap-sdt-devel
yum install -y perl-ExtUtils-Embed
yum install -y perl-ExtUtils-MakeMaker
yum install -y openssl
yum install -y openssl-devel
yum install -y pam
yum install -y pam-devel
yum install -y libxslt
yum install -y libxslt-devel
yum install -y systemd-devel
yum install -y tcl
yum install -y tcl-devel
3、编译安装
./configure --prefix=/usr/local/install/postgres/ --with-libxml --with-lz4 --enable-debug --with-perl --with-tcl --with-gssapi --with-pam --with-openssl --with-pam --without-ldap --with-libxml --with-libxslt --enable-dtrace --enable-depend --enable-cassert --with-systemd
gmake world && gmake install-world
4、配置环境变量
vim /etc/profile
export PGHOME=/usr/local/install/postgres
export PGDATA=/usr/local/install/postgres/data
export PGLIB=/usr/local/install/postgres/lib
export LC_ALL=en_US.UTF8
export LANG=en_US.UTF8
PATH=/usr/local/postgres/bin:$PATH
export PATH
source /etc/profile
5、创建文件
mkdir -p /usr/local/install/postgres/{data,backups,scripts,archive_wals}
mkdir -p /usr/local/install/postgres/pg_wal
chown -R postgres:postgres /usr/local/install/postgres/
6、初始化数据库
/usr/local/install/postgres/bin/initdb -D /usr/local/install/postgres/data/ -X /usr/local/install/postgres/pg_wal/ -W
7、设置开机自启
# 将源码包./contrib/start-scripts/linux 复制到/etc/init.d
cp ./contrib/start-scripts/linux /etc/init.d
# 修改名字为postgres
mv /etc/init.d/linux /etc/init.d/postgres
# 修改配置文件
vim /etc/init.d/postgresql
# prefix设置为你的安装路径
prefix=/usr/local/install/postgres
# pgdata设置为data路径
PGDATA=/usr/local/install/postgres/data
# PGUSER设置为操作postgreSQL的用户(默认为postgres)
PGUSER=postgres
# PGLOG是日志路径
# 分配权限
chmod a+x /etc/init.d/postgresql
# 添加开机启动
chkconfig --add postgresql
# 重启
reboot
# 查看启动状态
ps -ef|grep postgres