安装镜像仓库
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm -y
安装 PostgreSQL 11
yum install postgresql11 postgresql11-server -y
初始化数据库
/usr/pgsql-11/bin/postgresql-11-setup initdb
启动数据库
systemctl enable postgresql-11
systemctl start postgresql-11
开放防火墙
firewall-cmd --add-port=5432/tcp --permanent
firewall-cmd --reload
修改默认用户密码
su - postgres
psql -U postgres
alter user postgres with encrypted password 'abc123';
\q
exit
配置远程访问
vi /var/lib/pgsql/11/data/postgresql.conf
listen_address = '*'
vi /var/lib/pgsql/11/data/pg_hba.conf
host all all 0.0.0.0/0 md5
systemctl restart postgresql-11
新建用户
create user demo with password 'abc123';
新建数据库
CREATE DATABASE demo OWNER demo;
赋权
GRANT ALL PRIVILEGES ON DATABASE demo TO demo;