1.Postgresql官网获取特定版本的储存库。
Ubuntu 默认包含 PostgreSQL。要在 Ubuntu 上安装最新的 PostgreSQL, 使用命令:
sudo apt install postgresql
自动存储库配置:
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
要手动配置 Apt 存储库,按照下列步骤操作:
sudo apt install curl ca-certificates
sudo install -d /usr/share/postgresql-common/pgdg
sudo curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc
sudo sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
sudo apt update
sudo apt install postgresql-10
2.Postgresql创建账号、密码、赋予权限。
运行系统用户,进入Postgre客户端:
sudo -u postgres psql
创建用户“sde”并设置密码:
create user sde with password '123456';
赋予用户“sde”权限:
create database sde owner sde;
grant all privileges on database sde to sde;
3.允许Postgresql远程数据连接
进入Postgresql的安装目录,修改配置文件:pg_hba.conf和postgresql.conf。
cd /etc/postgresql/10/main
sudo gedit pg_hba.conf
sudo gedit postgresql.conf
在pg_hba.conf中在“# IPv4 local connections:”后加入
host all all 0.0.0.0/0 trust
在postgresql.conf中在“listen_addresses” 后面的=改为*。如 listen_addresses = '*'。若listen_addressde前面有#,将代码注释掉了的,需要去掉#。
修改完这两个文件后需要重启服务:
sudo service postgresl restart