centos 7安装postgresql10.3

最新版本安装请移步:阿里云服务器 centos 7 安装postgresql 11
一、Postgresql简介
官方网站:https://www.postgresql.org/
简介参考zhihu文章 https://www.zhihu.com/question/20010554
关于框架+DB的一些性能参考性能测试(仅供参考) http://www.techempower.com/benchmarks/#section=data-r15&hw=ph&test=fortune

DB-Engines Ranking TOP10(2018年3月仅供参考)

支持的系统:

二、Postgresql安装,比较小整体装起来非常快(不需要梯子)
参考官网地址:https://www.postgresql.org/download/linux/redhat/
1.安装rpm

yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

2.安装客户端(这一步可以在服务器端省略)

yum install postgresql10

3.安装服务端

yum install postgresql10-server

4.查看是否安装成功

rpm -aq| grep postgres


5.检查防火墙端口,并重启防火墙

firewall-cmd --permanent --add-port=5432/tcp
systemctl restart firewalld

6.初始化数据库并设置自动启动

/usr/pgsql-10/bin/postgresql-10-setup initdb
systemctl enable postgresql-10
systemctl start postgresql-10

7.查看启动状态

systemctl status postgresql-10


三、Postgresql配置

  1. 设置postgres的密码
    切换成postgres用户
su - postgres

登录postgres数据库

psql -U postgres

更改账号postgres的密码为postgres

ALTER USER postgres WITH PASSWORD 'postgres'

退出数据库

\q

切换成root账户,需输入密码

su root

完整命令截图,参考上面的指令
2. 修改远程访问ip
如果找不到文件路径就用截图里的find

vim /var/lib/pgsql/10/data/postgresql.conf


localhost改为*允许所有ip访问,真实环境请配置具体的ip地址

3. 修改访问策略
ADDRESS修改为samenet的意思是:匹配服务器所在子网中的任何地址 (因为我装的是虚拟机所以在一个网段里,线上环境请改为真实的IP地址)
METHOD修改为trust的意思是可信任

vim /var/lib/pgsql/10/data/pg_hba.conf

  1. 重启
systemctl restart postgresql-10

四、远程客户端访问

  1. 用Nacicat来连接,我的版本是11.1.x的感觉对pg的支持不是很好,建议还是用pgAdmin

  2. 用pgAdmin连接,下载地址(约154M) https://www.pgadmin.org/download/

posted @ 2018-03-20 23:19  nickchou  阅读(511)  评论(0编辑  收藏  举报