Ubuntu:安装PostgreSQL
1.输入以下命令安装PostgreSQL:
sudo apt install postgresql postgresql-contrib
2.查看运行状态
sudo service postgresql status
3.登录postgres账户
sudo su postgres
4.进入sql命令行
psql
5.创建数据库
create database test;
6.修改访问ip,允许远程访问
// 修改 postgresql.conf
// 默认是127.0.0.1,只能在本地访问
sudo gedit /etc/postgresql/12/main/postgresql.conf
//允许本机的任务一个ip地址访问postgresql
listen_addresses = '*'
// 修改pg_hba.conf
sudo gedit /etc/postgresql/12/main/pg_hba.conf
// 在文件中加入这一行
host all all 0.0.0.0/0 md5
备注:修改之后用pgadmin连接postgresql可能仍提示无法连接,可以尝试将pg_hba.conf中的md5全部修改为trust然后重启服务。
7.退出命令行
\q
8.重启服务
sudo service postgresql restart
END