ubuntu1904安装postgresql
1.安装命令
sudo apt update
sudo apt install postgresql postgresql-contrib
2. 测试安装
# 切换到postgres用户
sudo -i -u postgres
#访问postgresl
psql
#修改postgresl用户密码,等会用于远程连接,若不改连不上
ALTER USER postgres PASSWORD 'newPassword';
# 退出
\q
3.设置远程连接
3.1 修改postgresql用户密码
#切换postgres用户并进入psql
sudo -u postgres psql
#修改密码语句
ALTER USER postgres WITH PASSWORD '123456';
#退出
\q
3.2 修改配置文件
- postgresql.conf
- pg_hba.conf
3.2.1 postgresql.conf
# ***是你安装的版本,例如/etc/postgresql/10/main/postgresql.conf
vi /etc/postgresql/***/main/postgresql.conf
修改如下:
1. 去掉 #listen_addresses = 'localhost' 前面#号,并改为 listen_addresses = '*'
2. 去掉 #password_encryption = ***前面的#号
3.2.2 pg_hba.conf
vi /etc/postgresql/***/main/pg_hba.conf
在文档末尾加上以下内容
host all all 0.0.0.0/0 md5
3.2.3 重启服务
/etc/init.d/postgresql restart