安装服务

rpm -Uvh https://mirrors.aliyun.com/postgresql/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sed -i "s@https://download.postgresql.org/pub@https://mirrors.aliyun.com/postgresql@g" /etc/yum.repos.d/pgdg-redhat-all.repo
yum install -y postgresql15-server
/usr/pgsql-15/bin/postgresql-15-setup initdb
systemctl enable postgresql-15
systemctl start postgresql-15

配置用户

su - postgres
psql
ALTER USER postgres WITH PASSWORD 'postgres';
\q

退出postgres用户,此时密码为postgres

vim /var/lib/pgsql/15/data/postgresql.conf

将listen_address 修改为 *

vim /var/lib/pgsql/15/data/pg_hba.conf

在末尾添加
host all all 0.0.0.0/0 scram-sha-256

systemctl restart postgresql-15