1、安装命令
yum install postgresql-contrib postgresql-server -y
#查看是否安装成功
rpm -aq| grep postgres
初始化数据库
postgresql-setup initdb
网上的好多都是需要初始化的,不知道为啥我这没有初始化成功,好像不需要初始化
启动服务
systemctl start postgresql.service
添加开机加载服务
systemctl enable postgresql.service
查看版本
psql --version
2、修改用户密码
su -postgres
psql -U postgres
alter user postgres with password 'postgres'
\q # 退出
#切换root用户
su
#输入root密码
3、开启远程服务
# postgresql.conf
vi /var/lib/pgsql/data/postgresql.conf
# 修改为 *
listen_addresses = '*'
#pg_hba.conf
vim /home/pgsql/data/pg_hba.conf
host all all 0.0.0.0/0 trust
# 新增这一行,否则连接时会报错:Error connecting to the server:致命错误:没有用于主机“…”,用户“…”,数据库“…”,SSL关闭的pg_hba.conf记录:
重启服务
systemctl restart postgresql.service
开放防火墙端口
#查看防护墙状态
systemctl status firewalld
#忘记开了,重新开一下
systemctl status firewalld
#开放端口5432
firewall-cmd --add-port=5432/tcp --permanent
#刷新防火墙
firewall-cmd --reload
#查看防火墙开放端口
firewall-cmd --list-port
远程连接测试