PostgreSQL & PostGIS

安装postgresql

配置好yum源之后,使用yum info postgresql可发现 postgresql的版本为9.2.23,若想安装最新版本,可参考下面操作

https://www.postgresql.org/download/linux/redhat/

http://docs.nextgis.com/docs_ngweb/source/install-centos7.html

http://www.postgresonline.com/journal/archives/362-An-almost-idiots-guide-to-install-PostgreSQL-9.5,-PostGIS-2.2-and-pgRouting-2.1.0-with-Yum.html

sudo yum install https://download.postgresql.org/pub/repos/yum/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-3.noarch.rpm

# 查看上述仓库中可用的包
yum list | grep postgresql95
# 安装 PostgreSQL client server
sudo yum install postgresql95 postgresql95-server postgresql95-libs \
postgresql95-contrib postgresql95-devel
# 查看帮助
psql --help
rpm -qa | grep postgresql* # 查看已安装软件
# 初始化数据库,并设置随系统启动
sudo /usr/pgsql-9.5/bin/postgresql95-setup initdb
sudo systemctl start postgresql-9.5.service # service postgresql-9.5 start
sudo systemctl enable postgresql-9.5.service # 编辑验证参数(此处使用nano编辑器,可以使用 vim)
# psql 进入postgres数据库之后,使用 show hba_file; 查看文件位置
sudo nano /var/lib/pgsql/9.5/data/pg_hba.conf
sudo vim /var/lib/pgsql/9.5/data/pg_hba.conf

将ident 修改为 md5

PostgreSQL ident和peer基于操作系统用户的认证 PostgreSQL认证方法

如果是 peer,可能会出现 对等认证失败 的错误

# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# 可进一步修改 postgresql.conf 以监听目标地址
su postgres # 切换到postgres 或 sudo su postgres
psql -U postgres #登录数据库,默认没有密码
ALTER USER postgres WITH PASSWORD '密码'; #修改密码 sudo passwd postgres
# 或者使用 \password 命令
\password postgres
select * from pg_shadow; # 查看数据库信息
\q #退出
psql -V
sudo systemctl restart postgresql-9.5.service # 重启服务,或 service postgresql-9.5 restart # 使用postgres用户新建一个psql数据库用户(ngw_admin)
# \du 命令可以查看用户信息
# -P 表示密码,-e表示显示命令。 使用 -s 或 --superuser 赋予超级用户权限
sudo -u postgres createuser ngw_admin -P -e
# 新建数据库(db_ngw),所有者为 ngw_admin
sudo -u postgres createdb -O ngw_admin --encoding=UTF8 db_ngw
postgresql-client libraries and client binaries
postgresql-server core database server
postgresql-contrib additional supplied modules
postgresql-devel libraries and headers for C language development
pgadmin4 pgAdmin 4 graphical administration utility

安装postgis

https://postgis.net/install/

The postgis2_95-client contains the PostGIS commandline tools shp2gpsql, pgsql2shp, raster2pgsql that are useful for loading or exporting spatial data.

sudo yum install epel-release # 没有配置epel源的话
sudo yum install postgis2_95 postgis2_95-client # 安装
# 需要 pgRouting 时 yum install pgrouting_95
# 登录进入相应数据库
psql -U ngw_admin -d db_ngw
# 为已有数据库(db_ngw)扩展 postgis 功能
CREATE EXTENSION postgis;
SELECT PostGIS_Full_Version(); # 测试数据库是否包含了postgis的功能

或者直接在shell中执行

sudo psql -u postgres -d db_ngw -c 'CREATE EXTENSION postgis;'
sudo psql -u postgres -d db_ngw -c \
'ALTER TABLE geometry_columns OWNER TO ngw_admin;'
sudo psql -u postgres -d db_ngw -c \
'ALTER TABLE spatial_ref_sys OWNER TO ngw_admin;'
sudo psql -u postgres -d db_ngw -c \
'ALTER TABLE geography_columns OWNER TO ngw_admin;'
psql -h localhost -d db_ngw -U ngw_admin -c "SELECT PostGIS_Full_Version();"

使用template方式直接创建postgis数据库,并指定所有者

# 登录数据库
# postgis_21_sample 为 2.1 版本postgis数据库
create database geodataont template postgis_21_sample owner gdo;
# 或者
createdb -O gdo -U postgres -T postgis_22_sample geodataont

启用 PostGIS 功能的相关SQL

DO NOT INSTALL it in the database called postgres.

# 连接数据库之后,执行以下sql命令启用相应功能
# Enable PostGIS (includes raster)
CREATE EXTENSION postgis;
# Enable Topology
CREATE EXTENSION postgis_topology;
# Enable PostGIS Advanced 3D
# and other geoprocessing algorithms
# sfcgal not available with all distributions
CREATE EXTENSION postgis_sfcgal;
# fuzzy matching needed for Tiger
CREATE EXTENSION fuzzystrmatch;
# rule based standardizer
CREATE EXTENSION address_standardizer;
# example rule data set
CREATE EXTENSION address_standardizer_data_us;
# Enable US Tiger Geocoder
CREATE EXTENSION postgis_tiger_geocoder; CREATE EXTENSION pgrouting;
SELECT * FROM pgr_version();
# yum install ogr_fdw95
CREATE EXTENSION ogr_fdw;

CentOS 7 源码安装PostGIS

GIS on CentOS 7 之 PostgreSQL & PostGIS的更多相关文章

  1. 搭建简易Web GIS网站:使用GeoServer+PostgreSQL+PostGIS+OpenLayers3

    Web GIS系列: 搭建简易Web GIS网站:使用GeoServer+PostgreSQL+PostGIS+OpenLayers3 使用GeoServer+QGIS发布WMTS服务 使用GeoSe ...

  2. PostgreSQL+PostGIS

    PostGIS简介 PostGIS是对象关系型数据库系统PostgreSQL的一个扩展,PostGIS提供如下空间信息服务功能:空间对象.空间索引.空间操作函数和空间操作符.同时,PostGIS遵循O ...

  3. PostgreSql+PostGIS和uDig的安装

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.前言 总体来说,这两款开源软件均是很好安装的,一般按照提示一步一步 ...

  4. Linux CentOS 7 安装PostgreSQL 9.5.17 (源码编译)

    近日需要将PostgreSQL数据库从Windows中迁移到Linux中,Linux CentOS 7 安装PostgreSQL 9.5.17 安装过程 特此记录. 安装环境: 数据库:Postgre ...

  5. PostgreSQL+PostGIS的使用 函数清单

    一. PostgreSQL与PostGIS的关系 PostgreSQL 是世界上技术最先进的开源数据库,其前身是1977年一个源于Berkeley名为Ingres的非关系型数据库,其项目领导人为Mic ...

  6. GeoServer+PostgreSQL+PostGIS+pgRouting实现最短路径查询

    一.软件安装 GeoServer下载地址: http://geoserver.org/download/ PostgreSQL下载地址: https://www.postgresql.org/down ...

  7. PostgreSQL(PostGIS)安装和入门的若干问题

    1. 装完PostgreSQL后记得打开pgAdmin4启动一下服务器和启动一下数据库,否则PostGIS装不上. 2. pgAdmin4是网页,而3是客户端,当然都可以在File - Prefere ...

  8. PostgreSQL&PostGIS完全安装

    检查PostGIS.PostgreSQL.GEOS.GDAL.PROJ等各软件的版本依赖关系 http://trac.osgeo.org/postgis/wiki/UsersWikiPostgreSQ ...

  9. ubuntu16.04搭建geodjango+postgresql+postgis的WebGIS框架(一)安装第三方空间库

    postgis是postgresql的空间扩展对象,它需要一些第三方库的支持.包括GEOS, PROJ.4 和 GDAL.我们首先安装这几个空间库. 在ubuntu系统终端执行:(预先装一些依赖的库) ...

随机推荐

  1. js一种继承机制:用对象冒充继承构造函数的属性,用原型prototype继承对象的方法。

    js一种继承机制:用对象冒充继承构造函数的属性,用原型prototype继承对象的方法. function ClassA(sColor) { this.color = sColor; } ClassA ...

  2. kibana 与 grafana

    Kibana 和 Grafana 是两个开源工具,能可视化和推断大量日志数据内的趋势.Kibana 是一个分析和可视化平台,它可以让你浏览.可视化存储在Elasticsearch集群上排名靠前的日志数 ...

  3. ASP.NET网站权限设计实现(三)——套用JQuery EasyUI列表显示数据、分页、查询

    一.说明: JQuery EasyUI下载地址:http://jquery-easyui.wikidot.com/download,最新版本1.2.2. 首先预览一下界面: 本例实现的功能: 1.多标 ...

  4. Centos 配置ifconfig命令

    刚装完CentOS 后ifconfig命令可能是不可用的,那么需要以下配置 ip addr vi /etc/sysconfig/network-scripts/ifcfg-xx (ONBOOT=yes ...

  5. Elasticsearch 基础入门

    原文地址:Elasticsearch 基础入门 博客地址:http://www.extlight.com 一.什么是 ElasticSearch ElasticSearch是一个基于 Lucene 的 ...

  6. go的module用法

    新版不需要项目放在GOPATH里面了,这个恶心的机制之前还被n多人捧臭脚.简单列一下用法 新建项目 cd 项目目录go mod init 项目名 写好代码 go build 或者 go mod tid ...

  7. vue+node+mongoDB前后端分离个人博客(入门向)

    最近学习了VUE,自己为了学习做了个小小的博客,功能很简单,不过开发过程中也遇到了很多坑,所以记录下来方便以后使用.欢迎大家交流学习. 功能 实现了用户注册.登录.token检测登录.用户留言.个人中 ...

  8. 关于后台程序java报错问题解决

    HTTP Status – Internal Server Error Type Exception Report Message Handler processing failed; nested ...

  9. charles只获取指定的请求的设置方法

    过滤网络请求 通常情况下,需要对网络请求进行过滤,只监控指定服务器的请求.有3种办法: 方法一:在主界面的中部的 Filter 栏中输入需要过滤出来的关键字.例如我们的服务器的地址(host)是:ww ...

  10. Ubuntu14.04配置jdk1.8.0_25,可切换版本

    下载jdk:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 解压: sudo m ...