1. 进入PostgreSQL官网:https://www.postgresql.org/download/linux/redhat/
  2. 选择软件版本和系统版本
  3. 在服务器上执行脚本,以CentOS7.4和PostgreSQL13为例
# Install the repository RPM:
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

# Install PostgreSQL:
sudo yum install -y postgresql13-server

# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-13/bin/postgresql-13-setup initdb
sudo systemctl enable postgresql-13
sudo systemctl start postgresql-13
  1. 远程连接,密码配置
    1. 配置文件路径/var/lib/pgsql/13/data/pg_hba.conf。修改127.0.0.1/32为0.0.0.0/0
    2. 配置文件路径/var/lib/pgsql/13/data/postgresql.conf。修改listen_address="*",取消port=5432的注释
    3. 重启postgresql
    4. 配置防火墙,放行5432端口
    sudo firewall-cmd --permanent --add-port=5432/tcp 
    sudo firewall-cmd –reload
    
    1. 修改密码
    su – postgres
    psql
    ALTER USER postgres WITH PASSWORD '这里输入你的密码';
    \q
    exit