原文链接:https://blog.youkuaiyun.com/chuckchen1222/article/details/83186756
原文链接:https://www.landui.com/help/show-7740
首先,到官网查看yum支持到哪个版本的Postgresql
https://yum.postgresql.org/repopackages.php
点击下载,获取下载路径
https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
安装RPM包
yum install -y https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-7-x86_64/pgdg-centos11-11-2.noarch.rpm
安装数据库
yum install -y postgresql11
yum install postgresql11-server
然后初始化数据库
/usr/pgsql-11/bin/postgresql-11-setup initdb
开机启动
systemctl enable postgresql-11
启动
systemctl start postgresql-11
允许远程登陆
vi /var/lib/pgsql/11/data/postgresql.conf
修改listen_addresses = ‘*’
修改pg.hba文件需要重启服务
vim /var/lib/pgsql/11/data/pg_hba.conf
添加 host all all 0.0.0.0/0 md5
修改登录密码
sudo -u postgres psql
alter user postgres with password ‘123456’;
创建新用户
create user cyz with password ‘123456’;
创建数据库同时指定数据库的所有者
create database test owner cyz;
数据库赋权未赋权则账户只能登录控制台
grant all privileges on database test to cyz;
\q 退出
开放端口-防火墙
firewall-cmd --get-active-zones
添加端口到防火墙中
firewall-cmd --zone=public --add-port=5432/tcp --permanent
防火墙重新读取端口列表
firewall-cmd --reload
重启数据库
systemctl restart postgresql-11