操作系统信息:

安装PostgreSQL:
1.安装rpm文件
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2.安装客户端
yum install postgresql10
3.安装服务端
yum install postgresql10-server
4.初始化
/usr/pgsql-10/bin/postgresql-10-setup initdb
5.启动PostgreSQL服务
systemctl start postgresql-10
服务启动、关闭、重启、查看状态命令
systemctl start postgresql-10
systemctl stop postgresql-10
systemctl restart postgresql-10
systemctl status postgresql-10
6.将PostgreSQL服务设置为开机自启动
systemctl enable postgresql-10
创建用户和数据库:
1.使用postgres用户登录(PostgreSQL安装后会自动创建postgres用户,无密码)
su postgres

2.登录PostgreSQL数据库

3.创建用户和数据库授权
创建用户test_user,并设置密码为123456
create user test_user with password '123456';
为用户test_user创建数据库test_db
create database test_db owner test_user;
授权
grant all privileges on database test_db to test_user;

4.退出PostgreSQL数据库
\q

开启远程访问:
1.修改postgresql.conf配置文件,取消listen_address的注释,将参数值修改为*
postgresql.conf一般在/var/lib/pgsql/data/目录中,如果不在可以通过find命令进行查找,我的在/var/lib/pgsql/10/data/目录中;



2.修改pg_hba.conf文件,增加下图红框部分内容
pg_hba.conf与postgresql.conf在同一目录中;

3.使用root用户重启PostgreSQL服务
systemctl restart postgresql-10.service
4.使用链接工具测试连接
如果连接不成功可以关闭防火墙再进行连接哦~

参考地址:https://blog.csdn.net/sinat_26594945/article/details/107715171
网友评论