下载yum软件源
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
下载依赖安装包
mkdir pg12_rpm_packs
yum install --downloadonly --downloaddir=./pg12_rpm_packs postgresql12-server postgresql12 postgresql12-contrib
压缩
tar -czvf pg12_rpm_packs.tar.gz pg12_rpm_packs
按照顺序安装
rpm -ivh postgresql12-libs-12.6-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql12-12.6-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql12-server-12.6-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql12-contrib-12.6-1PGDG.rhel7.x86_64.rpm
rpm -ivh libicu-50.2-4.el7_7.x86_64.rpm
rpm -ivh libxslt-1.1.28-6.el7.x86_64.rpm
创建目录
mkdir -p /data/pgsql/data
mkdir -p /data/pgsql/logs
环境变量
PGHOME=/usr/pgsql-12
export PGHOME
PGDATA=/data/pgsql/data
export PGDATA
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin
export PATH
source /etc/profile
创建用户
#新建用户
adduser postgres
#强制设置密码
passwd --stdin postgres
#修改此用户postgres相关文件夹的归属
chown -R postgres:postgres /usr/pgsql-12
chown -R postgres:postgres /data/pgsql
#赋予此用户postgres相关文件夹的权限
chmod -R 777 /usr/pgsql-12
chmod -R 777 /data/pgsql
初始化数据库
cd /usr/pgsql-12/bin/
initdb -D /data/pgsql/data
配置文件
/var/lib/pgsql/12/data/postgresql.conf