下载yum软件源

    1. yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

    下载依赖安装包

    1. mkdir pg12_rpm_packs
    2. yum install --downloadonly --downloaddir=./pg12_rpm_packs postgresql12-server postgresql12 postgresql12-contrib

    压缩

    1. tar -czvf pg12_rpm_packs.tar.gz pg12_rpm_packs

    按照顺序安装

    1. rpm -ivh postgresql12-libs-12.6-1PGDG.rhel7.x86_64.rpm
    2. rpm -ivh postgresql12-12.6-1PGDG.rhel7.x86_64.rpm
    3. rpm -ivh postgresql12-server-12.6-1PGDG.rhel7.x86_64.rpm
    4. rpm -ivh postgresql12-contrib-12.6-1PGDG.rhel7.x86_64.rpm
    5. rpm -ivh libicu-50.2-4.el7_7.x86_64.rpm
    6. rpm -ivh libxslt-1.1.28-6.el7.x86_64.rpm

    创建目录

    1. mkdir -p /data/pgsql/data
    2. mkdir -p /data/pgsql/logs

    环境变量

    1. PGHOME=/usr/pgsql-12
    2. export PGHOME
    3. PGDATA=/data/pgsql/data
    4. export PGDATA
    5. PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin
    6. export PATH
    7. source /etc/profile

    创建用户

    1. #新建用户
    2. adduser postgres
    3. #强制设置密码
    4. passwd --stdin postgres
    5. #修改此用户postgres相关文件夹的归属
    6. chown -R postgres:postgres /usr/pgsql-12
    7. chown -R postgres:postgres /data/pgsql
    8. #赋予此用户postgres相关文件夹的权限
    9. chmod -R 777 /usr/pgsql-12
    10. chmod -R 777 /data/pgsql

    初始化数据库

    1. cd /usr/pgsql-12/bin/
    2. initdb -D /data/pgsql/data

    配置文件

    1. /var/lib/pgsql/12/data/postgresql.conf