PostgreSql和PostGIS安装——Windows10家庭版
1、系统环境:Windows 10 家庭中文版
2、PostgreSql:postgresql-11.2-1-windows-x64
3、PostGIS:postgis-bundle-pg11x64-setup-3.1.0-1.exe
二、下载地址
PostgreSql:https://get.enterprisedb.com/postgresql/postgresql-11.2-1-windows-x64.exe
PostGIS:可以直接通过安装postgreSql时下载,其它下载渠道:http://download.osgeo.org/postgis/windows/pg11/
三、安装异常
本来想安装:postgresql-12.5-1-windows-x64,但是安装报以下错误,所以选择了11.2.1版本。
四、PostgreSQL安装过程和postgis下载
我修改了安装路径:D:oyz3dserverPostgreSQL11
第1个筛选框:安装PostgreSql服务。
第2个筛选框:安装paAdmin客户端,用于连接操作postgreSql数据库。
第3个筛选框:安装结束后,可以打开新窗口,安装postgresql相关的其它插件,比如:PostGIS.
第4个筛选框:必选,未知。
设置数据库密码:123456
设置数据库端口号:5432
到至postgresql安装完成。以下是下载PostGis,但是下载很慢,建议下载地址:http://download.osgeo.org/postgis/windows/pg11/
选择PostGIS的版本(3个任选其一)和下载位置。
五、PostGIS安装
六、其它操作
1、在命令行输入:services.msc 打开服务,可以看到postgresql数据默认已设置为开机启动
2、加入全局环境变量
3、测试PostGIS是否安装成功
Microsoft Windows [版本 10.0.18363.1316] (c) 2019 Microsoft Corporation。保留所有权利。 #######连接登录postgresql数据库 C:Userszhao>psql -U postgres -h localhost -d postgres -p 5432 用户 postgres 的口令: psql (11.2) 输入 "help" 来获取帮助信息. #######创建test数据库 postgres=# create database test; CREATE DATABASE #######切换test数据库 postgres=# c test; 您现在已经连接到数据库 "test",用户 "postgres". #######创建postgis扩展 test=# create extension postgis; CREATE EXTENSION #######查询全部扩展 test=# select postgis_full_version(); postgis_full_version ---------------------------------------------------------------------------------------------------------------------------------------------------------------- POSTGIS="3.1.0 3.1.0" [EXTENSION] PGSQL="110" GEOS="3.9.0-CAPI-1.14.1" PROJ="7.1.1" LIBXML="2.9.9" LIBJSON="0.12" LIBPROTOBUF="1.2.1" WAGYU="0.5.0 (Internal)" (1 行记录) test=#
七、配置数据库远程访问
PG默认只能本机访问,但是实际情况中,应用服务器多单独部署,需要开通PG的远程访问权限,且是需要配置用户密码的。
需要修改postgres.conf, pg_hba.conf文件。
文件位置:
D:oyz3dserverPostgreSQL11datapostgresql.conf
D:oyz3dserverPostgreSQL11datapg_hba.conf
修改postgresql.conf
#listen_addresses='localhost'
listen_addresses='*' --- 修改成'*'全部ip都可以访问改数据库。
修改pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD # IPv4 local connections: host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128 md5 # Allow replication connections from localhost, by a user with the # replication privilege. host replication all 127.0.0.1/32 md5 host replication all ::1/128 md5 host all all 0.0.0.0/0 md5 --添加本行数据
注意: 重启pg数据库