1. yum安装

# 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 postgresql14-server

# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14

2. 设置

/var/lib/pgsql/14/data/postgresql.conf
listen_addresses = '*'
/var/lib/pgsql/14/data/pg_hba.conf
host all all 0.0.0.0/0 md5

3. 建库

su - postgres
psql
sql
create database 数据库名;
create user 用户名 with password '密码';
GRANT ALL PRIVILEGES ON DATABASE 数据库名 to 用户名;
  1. 查看用户: \du

  2. 退出: \q

4. 防火墙设置

sudo firewall-cmd --zone=public --add-port=5432/tcp --permanent
sudo firewall-cmd --reload
sudo firewall-cmd --zone=public --list-ports