PostgreSQL安装、使用

2017-10-21  本文已影响0人  数大招疯

一、安装

1.在官网选择对应系统的版本:

2.使用yum安装

yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm 
yum install postgresql96
yum install postgresql96-server
/usr/pgsql-9.6/bin/postgresql96-setup initdb

3.启动、停止服务

systemctl start postgresql-9.6
systemctl stop postgresql-9.6
systemctl restart postgresql-9.6

二、配置(修改配置文件需要重启服务)

1. 修改用户密码

su - postgres
alter user postgres with password '123456'

2. 允许远程访问

sed -i "s|#listen_addresses = 'localhost'|listen_addresses = '*'|g" /var/lib/pgsql/9.6/data/postgresql.conf

3. 添加主机认证

vim /var/lib/pgsql/9.6/data/pg_hba.conf
host    all             all             172.26.126.26/32          trust

“host” 代表主机类型,
第一个“all”代表db,
第二个“all”代表user ,
“172.26.126.26/32” 代表client ip,“trust”代表认证方式;
认证方式除“trust”外,还有“peer”, “ident”, “md5”, “password”等,具体可参考pg-hba文件: https://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html

上一篇下一篇

猜你喜欢

热点阅读