sentos7安装postgresql

  1. 安装服务器即可。

Yum install postgresql-server

Yum install postgresql-contrib

  1. 验证是否安装成功:

rpm -aq| grep postgres

  1. 安装完成后,检查postgresql的服务状态

Systemctl status postgresql (一般不成功)

安装postgresql后需要初始化数据库

执行postgresql-setup initdb

4 .再次启动postgresql服务

Systemctl status postgresql

5.启用开机自启动

systemctl enable postgresql-10
systemctl start postgresql-10
6.配置防火墙

firewall-cmd --permanent --add-port=5432/tcp
firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
7.修改用户密码

su - postgres  切换用户,执行后提示符会变为 '-bash-4.2$'
psql -U postgres 登录数据库,执行后提示符变为 'postgres=#'
ALTER USER postgres WITH PASSWORD 'postgres'  设置postgres用户密码为postgres
\q  退出数据库

8.开启远程访问

 vim /var/lib/pgsql/10/data/postgresql.conf
修改#listen_addresses = 'localhost'  为  listen_addresses='*'
当然,此处‘*’也可以改为任何你想开放的服务器IP

9.信任远程连接

vi m/var/lib/pgsql/10/data/pg_hba.conf
修改如下内容,信任指定服务器连接
# IPv4 local connections:
host    all            all      127.0.0.1/32      trust
host    all            all      192.168.157.1/32(需要连接的服务器IP)  trust

10.重启服务

systemctl restart postgresql-10

11.postsql数据库命令

psql -U postgres
出现以下界面,说明已经进入到想要的数据库,可以进行想要的操作了。

template1=# 。比如:
\l --查看系统中现存的数据库

create database test1DBName; --创建数据库
\d --查看数据库列表:
12 .安装pgadmin4客户端连接linux中安装的postgresql。

你可能感兴趣的:(sentos7安装postgresql)