Ubuntu安装PostgreSQL

 系统环境:

操作系统:Ubuntu 16.04

数据库:PostgreSQL 9.3  

 安装PostgreSQL

  • 修改apt源
# vim /etc/apt/sources.list.d/pgdg.list

############################
## 根据系统版本添加下面这行
############################

## 14.04
deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main

## 16.04
deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main

## 17.04
deb http://apt.postgresql.org/pub/repos/apt/ zesty-pgdg main  

# apt update
  • 安装PostgreSQL
## xxx替换为版本号,此处是9.3
sudo apt install postgresql-xxx  
  • 编辑 /etc/postgresql/9.5/main/postgresql.conf
将下面 listen_addresses = 'localhost'注释去掉并改为  listen_addresses = '*'
# - Connection Settings -
#listen_addresses = 'localhost'          
# what IP address(es) to listen on;                
# comma-separated list of addresses;     
# defaults to 'localhost'; use '*' for all
...

将下面password_encryption = on 注释打开
#password_encryption = on   
  • 切换用户
su - postgres
  • 通过 psql 命令进入postgresql客户端,修改用户密码:
ALTER USER postgres PASSWORD '123456';   
  •  修改pg_hba文件
# vim /etc/postgresql/9.5/main/pg_hba.conf

#################################################################
## 修改 host all all 192.168.1.0/24 md5 中的ip,为:0.0.0.0/0
#################################################################

# TYPE DATABASE  USER    CIDR-ADDRESS     METHOD
# "local" is for Unix domain socket connections only
local all    all               trust
# IPv4 local connections:
host  all    all    127.0.0.1/32     trust
host  all    all    192.168.1.0/24    md5
# IPv6 local connections:
host  all    all    ::1/128       trust  
  • 启动服务:
## 此处xx为9.3
sudo systemctl start postgresql@xx-main.service  

 博客参考链接 

https://blog.csdn.net/ax7399/article/details/78210051

https://www.jianshu.com/p/dda94c4ffd52

  

 

posted @ 2018-09-28 18:06  evescn  阅读(274)  评论(0编辑  收藏  举报