【PostgreSQL+PostGIS离线安装】2天的踩坑及问题解决经验分享(含安装文件postgresql-9.5.9+postgis-2.2.3+多个依赖及测试SQL)
生活随笔
收集整理的這篇文章主要介紹了
【PostgreSQL+PostGIS离线安装】2天的踩坑及问题解决经验分享(含安装文件postgresql-9.5.9+postgis-2.2.3+多个依赖及测试SQL)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
資源分享【有的安裝包比較難下載】
鏈接:https://pan.baidu.com/s/1XPUoyReHOKyjNINpcyrMRQ
提取碼:9f26
包含資源:
1.準備
# 組件安裝 yum -y install gcc yum -y install bzip2 yum -y install autoconf yum -y install zlib-devel yum -y install gcc gcc-c++ yum -y install readline-devel # 添加用戶組和用戶(postgreSQL不能以root用戶運行) groupadd postgres useradd -g postgres postgres passwd postgres2.安裝PostgreSQL
# 1.解壓 tar -zxvf postgresql-9.5.9.tar.gz # 2.在解壓的目錄內執行命令: prefix為安裝目錄 ./configure –prefix=/usr/local/pgsql # 這個階段要注意error信息,解決完全部error后再進行安裝。 make make install# 3.環境變量配置 vi /etc/profile# ---添加配置---export LD_LIBRARY_PATH=/usr/local/pgsql/lib:$LD_LIBRARY_PATHexport PATH=/usr/local/pgsql/bin:$PATHexport MANPATH=/usr/local/pgsql/man:$MANPATH # ---配置生效--- source /etc/profile# 4.在/usr/local/pgsql文件夾下創建數據庫數據文件夾 mkdir /usr/local/pgsql/data chown -R postgres.postgres /usr/local/pgsql/data# 切換為postgres用戶 su postgres# 5.在/usr/local/pgsql/bin文件夾下執行數據庫初始化 # 設置locale為C,并且template編碼為UNICODE,使數據庫支持中文 ./initdb --locale=C -E UNICODE -D ../data/# 6.使用root用戶,更改日志文件的屬主為postgres,修改后切回postgres用戶 chown postgres /var/log/pgsql.log# 7.修改配置/usr/local/pgsql/data vi postgresql.conf # 使監聽生效 listen_addresses='*' port=5432vi pg_hba.conf host all all 0.0.0.0/0 md5# 8.設置密碼 /usl/local/pgsql/bin/ 否則用戶postgres無法連接數據庫 psql ALTER USER postgres WITH PASSWORD 'postgres'; # 9.啟動停止數據庫 /usl/local/pgsql/bin/ ./pg_ctl start -D /usr/local/pgsql/data/ ./pg_ctl stop -D /usr/local/pgsql/data/3.安裝PostGIS
安裝PostGIS之前須先安裝proj4,geos,libxml2,gdal2,json-c,protobuf
1.安裝proj4
# 1.解壓 配置 編譯 安裝 tar -zxvf proj-4.8.0.tar.gz cd proj-4.8.0 ./configure --prefix=/opt/proj-4.8.0 make make install# 2.庫的路徑添加到系統中 vi /etc/ld.so.conf.d/proj-4.8.0.conf# ---添加配置---/opt/proj-4.8.0/lib # 配置生效 ldconfig2.安裝geos
# 1.解壓 配置 編譯 安裝 tar -jxvf geos-3.3.7.tar.bz2 cd geos-3.3.7 ./configure --prefix=/opt/geos-3.3.7 make make install# 2.庫的路徑添加到系統中 vi /etc/ld.so.conf.d/geos-3.3.7.conf# ---添加配置---/opt/geos-3.3.7/lib # 配置生效 ldconfig3.安裝libxml2
方式相同
4.安裝gdal2
方式相同,make階段時間較長(半小時)
5.安裝json-c
方式相同
6.安裝protobuf
方式相同,make階段時間較長(20分鐘左右)
7.安裝postgis
安裝前
# 解決gdal無法獲取的問題 vi /etc/ld.so.conf# ---配置---include /etc/ld.so.conf.d/*.conf/usr/local/pgsql/lib# 使配置生效 ldconfig –v安裝
tar -zxvf postgis-2.2.3.tar.gz cd postgis-2.2.3 # 具體目錄要根據擴展文件安裝目錄而定 ./configure --prefix=/opt/postgis --with-pgconfig=/usr/local/pgsql/bin/pg_config --with-geosconfig=/opt/geos-3.3.7/bin/geos-config --with-projdir=/opt/proj-4.9.3/ --with-xml2config=/opt/libxml2-2.6.26/bin/xml2-config --with-gdalconfig=/opt/gdal-2.1.2/bin/gdal-config make make install4.PostGIS驗證(copy)
-- 建表 CREATE TABLE cities ( id int4, name varchar(50) ); -- 添加位置字段 SELECT AddGeometryColumn ('cities', 'the_geom', 4326, 'POINT', 2); -- 插入幾條數據 INSERT INTO cities (id, the_geom, name) VALUES (3,ST_GeomFromText('POINT(-5.911 3.015)',4326),'BeiJing,China'); -- 查詢全表 select id,name,ST_AsText(the_geom) from cities ; -- 查詢任意兩點間球面距離,并以id排序 SELECT p1.name,p2.name,ST_Distance_Sphere(p1.the_geom,p2.the_geom) FROM cities AS p1, cities AS p2 WHERE p1.id > p2.id; -- 查詢矩形內的點 select id, name, ST_AsText(the_geom) from cities where the_geom && ST_SetSRID(ST_MakeBox2D(ST_POINT(-10.0,-10.0),ST_POINT(10.0,10.0)),4326); -- 任意給出幾個點,查詢該空間范圍內的點,第一個點和最后一個點應是同一個點 select id,name,ST_AsText(cities.the_geom) from cities where the_geom && ST_AsText(ST_MakePolygon(ST_GeomFromText('LINESTRING ( -10.31 10.97 , -10.15 -10.09 , 10.35 10.27 , 10.31 -10.97 , -10.31 10.97)'))); -- 同上 select id,name,ST_AsText(cities.the_geom) from cities where the_geom && ST_MakePolygon(ST_GeomFromText('LINESTRING ( -10.31 10.97 , -10.15 -10.09 , 10.35 10.27 , 10.09 -10.88 , 30.31 -40.97 , -1.11 60.33 , -10.31 10.97)')); -- string應該用單引號,雙引號會報錯 update cities set name = 'America,LAS' where id = 5; -- 刪除數據 delete from cities where id = 33; -- 查詢距離點(-87.71 43.741)距離為151600000米的所有點 SELECT name,st_astext(the_geom) FROM cities WHERE ST_DWithin(ST_Transform(ST_GeomFromText('POINT(-87.71 43.741)',4326),26986),ST_Transform(the_geom,26986), 151600000);5.總結
離線安裝PostgreSQL稍顯繁瑣【主要是用戶的切換】,PostGIS插件的安裝出現報錯信息解決就好,也不是很麻煩。
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的【PostgreSQL+PostGIS离线安装】2天的踩坑及问题解决经验分享(含安装文件postgresql-9.5.9+postgis-2.2.3+多个依赖及测试SQL)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ClickHouse【环境搭建 02】设
- 下一篇: ClickHouse【资源分享 01】L