Postgresql11.3安装Postgis

安装插件要求需要预先安装 GEOS, Proj, GDAL, LibXML2 和 JSON-C。这里我们只有GEOS,GDAL和Proj没有安装。其他如果没有安装的,也记得安装即可。

以下可见我已经安装,这两个一般系统自带就可以安装。

# rpm -qa | grep libxml
libxml2-devel-2.7.6-20.el6.x86_64
perl-libxml-perl-0.08-10.el6.noarch
libxml2-python-2.7.6-20.el6.x86_64
libxml2-2.7.6-20.el6.x86_64
# rpm -qa | grep json-c
json-c-devel-0.11-13.el6.x86_64
json-c-doc-0.11-13.el6.noarch
json-c-0.11-13.el6.x86_64
下载需要的软件,然后编译安装
wget http://download.osgeo.org/proj/proj-4.9.3.tar.gz
wget http://download.osgeo.org/geos/geos-3.7.3.tar.bz2
wget https://download.osgeo.org/gdal/2.4.4/gdal-2.4.4.tar.gz

tar -jxvf geos-3.7.3.tar.bz2
cd geos-3.7.3/
./configure --prefix=/usr/local/geos-3.7.3
make -j8 && make install

tar -zxvf proj-4.9.3.tar.gz
cd proj-4.9.3/
./configure --prefix=/usr/local/proj-4.9.3
make -j8 && make install

tar -zxvf gdal-2.4.4.tar.gz
cd /opt/gdal-2.4.4/
./configure --prefix=/usr/local/gdal-2.4.4
make -j8 && make install
下载Postgis
这里由于速度太慢,我用了代理
curl -O -x 163.53.171.186:443 -k -L https://download.osgeo.org/postgis/source/postgis-3.0.1.tar.gz
当然也可以
wget https://download.osgeo.org/postgis/source/postgis-3.0.1.tar.gz
tar zxvf postgis-3.0.1.tar.gz 
cd postgis-3.0.1/
./configure --prefix=/usr/local/postgis-3.0.1 --with-pgconfig=/opt/pgsql11.3/bin/pg_config --with-geosconfig=/usr/local/geos-3.7.3/bin/geos-config --with-gdalconfig=/usr/local/gdal-2.4.2/bin/gdal-config --with-projdir=/usr/local/proj-4.9.3 --with-jsondir=/usr

make -j8 && make install 
进入数据库,用所需用户直接创建插件,以下报错,直接拷贝对应的.so文件即可,这里我开了两个窗口,一个窗口看报错,一个窗口复制文件到相应路径。直到没有报错成功创建即可。
psql -p 1921
psql (11.3)
Type "help" for help.
hank=# \c  hank postgres
You are now connected to database "hank" as user "postgres".
hank=# create extension postgis;
ERROR:  could not load library "/opt/pgsql11.3/lib/postgis-3.so": libgeos_c.so.1: cannot open shared object file: No such file or directory
hank=# create extension postgis;
ERROR:  could not load library "/opt/pgsql11.3/lib/postgis-3.so": libproj.so.12: cannot open shared object file: No such file or directory
hank=# create extension postgis;
CREATE EXTENSION
hank=# create extension postgis_topology
CREATE EXTENSION
解决以上报错,只需要把对应的文件拷贝到相应目录即可,最后成功安装插件
# find / -name "libgeos_c.so.1"
/usr/local/geos-3.7.3/lib/libgeos_c.so.1
/opt/geos-3.7.3/capi/.libs/libgeos_c.so.1
# cp /usr/local/geos-3.7.3/lib/libgeos_c.so.1 /opt/pgsql11.3/lib
# chown -R postgres.postgres /opt/pgsql11.3/lib/libgeos_c.so.1 
# find / -name "libproj.so.12"                                  
/usr/local/proj-4.9.3/lib/libproj.so.12
/opt/proj-4.9.3/src/.libs/libproj.so.12
# cp /usr/local/proj-4.9.3/lib/libproj.so.12 /opt/pgsql11.3/lib
安装postgis_raster,postgis_tiger_geocoder,address_standardizer和address_standardizer_data_us
安装报错
hank=# create extension postgis_raster;
ERROR:  could not load library "/opt/pgsql11.3/lib/postgis_raster-3.so": libgdal.so.20: cannot open shared object file: No such file or directory

找到so文件复制到数据库lib目录下
# find / -name "libgdal.so.20"                                 
/usr/local/gdal-2.4.2/lib/libgdal.so.20
/opt/gdal-2.4.2/.libs/libgdal.so.20
You have new mail in /var/spool/mail/root
# cp /usr/local/gdal-2.4.2/lib/libgdal.so.20 /opt/pgsql11.3/lib
hank=# create extension postgis_raster;              
CREATE EXTENSION
hank=# create extension postgis_tiger_geocoder ;     
ERROR:  required extension "fuzzystrmatch" is not installed
HINT:  Use CREATE EXTENSION ... CASCADE to install required extensions too.
hank=# create extension fuzzystrmatch ;
CREATE EXTENSION
hank=# create extension postgis_tiger_geocoder ;
CREATE EXTENSION
hank=# create extension address_standardizer;
CREATE EXTENSION
hank=# create extension address_standardizer_data_us ;
CREATE EXTENSION
hank=# SELECT name, default_version,installed_version
FROM pg_available_extensions WHERE name LIKE 'postgis%' or name LIKE 'address%';
             name             | default_version | installed_version 
------------------------------+-----------------+-------------------
 postgis_topology             | 3.0.1           | 3.0.1
 postgis_raster               | 3.0.1           | 3.0.1
 postgis_tiger_geocoder       | 3.0.1           | 3.0.1
 address_standardizer         | 3.0.1           | 3.0.1
 address_standardizer_data_us | 3.0.1           | 3.0.1
 postgis                      | 3.0.1           | 3.0.1
(6 rows)

至此,所有安装完成。

参考:http://www.postgis.net/docs/manual3.0/postgis_installation.html

你可能感兴趣的:(#,postgreSQL)