版本:PostgreSQL 11.20
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
rpm -ql pgdg-redhat-repo
yum install postgresql11 postgresql11-server -y
# 把自动创建的postgres用户删除
userdel -r postgres
groupadd -g 701 postgres
useradd -g 701 -u 701 -s /bin/bash -m postgres
passwd postgres
su postgres
mkdir /home/postgres/pgdata
cd /home/postgres
vi .bashrc
export PATH=/usr/pgsql-11/bin:$PATH
export LD_LIBRARY_PATH=/usr/pgsql-11/lib:$LD_LIBRARY_PATH
export PGDATA=/home/postgres/pgdata
export PGHOST=/tmp
source .bashrc
su - postgres
initdb
vim /home/postgres/pgdata/postgresql.conf
# 修改端口和绑定地址
listen_addresses = '*'
port = 15432
vim pg_hba.conf
# 添加一行
host all all 0.0.0.0/0 trust
# 进入数据库修改密码
psql -U postgres -p 15432
ALTER USER postgres WITH PASSWORD 'postgres';
# 启动数据库
pg_ctl start
# 停止数据库
pg_ctl stop