postgresql9.6安装postgis


postgresql9.6安装postgis

实验环境

操作系统:CentOS 7
数据库系统: PostgreSQL 9.6

问题重现:

创建表:

DROP TABLE IF EXISTS "jq_common"."tbl_geo_marker_pattern";
CREATE TABLE "jq_common"."tbl_geo_marker_pattern" (
"id" int8 DEFAULT nextval('tbl_geo_marker_pattern_id_seq1'::regclass) NOT NULL,
"marker_id" int8 NOT NULL,
"pattern_type" varchar COLLATE "default",
"gps_geometry" "public"."geometry",
"radius" float8
);

报错:

[Err] ERROR:  type "public.geometry" does not exist
LINE 6: "gps_geometry" "public"."geometry",
                       ^

发现缺少postgis插件。

添加postgis插件:

create extension postgis;
[Err] ERROR:  could not open extension control file "/usr/pgsql-9.6/share/extension/postgis.control": No such file or directory

发现本机未安装postgis插件。

安装postgis插件:

[root@plat-ecloud01-db-postgres07 ~]# yum install postgis

--> Finished Dependency Resolution
Error: Package: gdal-libs-1.11.4-12.rhel7.x86_64 (pgdg96)
           Requires: libdapserver.so.7()(64bit)
Error: Package: gdal-libs-1.11.4-12.rhel7.x86_64 (pgdg96)
           Requires: libdap.so.17()(64bit)
Error: Package: gdal-libs-1.11.4-12.rhel7.x86_64 (pgdg96)
           Requires: libarmadillo.so.8()(64bit)
Error: Package: gdal-libs-1.11.4-12.rhel7.x86_64 (pgdg96)
           Requires: libogdi.so.3()(64bit)
Error: Package: gdal-libs-1.11.4-12.rhel7.x86_64 (pgdg96)
           Requires: libCharLS.so.1()(64bit)
Error: Package: gdal-libs-1.11.4-12.rhel7.x86_64 (pgdg96)
           Requires: libgta.so.0()(64bit)
Error: Package: gdal-libs-1.11.4-12.rhel7.x86_64 (pgdg96)
           Requires: libnetcdf.so.7()(64bit)
Error: Package: gdal-libs-1.11.4-12.rhel7.x86_64 (pgdg96)
           Requires: libfreexl.so.1()(64bit)
Error: Package: gdal-libs-1.11.4-12.rhel7.x86_64 (pgdg96)
           Requires: libcfitsio.so.2()(64bit)
Error: Package: gdal-libs-1.11.4-12.rhel7.x86_64 (pgdg96)
           Requires: libdapclient.so.6()(64bit)
Error: Package: gdal-libs-1.11.4-12.rhel7.x86_64 (pgdg96)
           Requires: libopenjp2.so.7()(64bit)
Error: Package: postgis24_96-2.4.5-1.rhel7.x86_64 (pgdg96)
           Requires: hdf5
Error: Package: gdal-libs-1.11.4-12.rhel7.x86_64 (pgdg96)
           Requires: libhdf5.so.8()(64bit)
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

由于缺少必要包,导致安装失败。

问题解决

安装依赖包:

[root@plat-ecloud01-db-postgres07 ~]# rpm -ivh ftp://bo.mirror.garr.it/1/slc/centos/7.0.1406/extras/x86_64/Packages/epel-release-7-5.noarch.rpm
Retrieving ftp://bo.mirror.garr.it/1/slc/centos/7.0.1406/extras/x86_64/Packages/epel-release-7-5.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:epel-release-7-5                 ################################# [100%]

再安装postgis:

[root@plat-ecloud01-db-postgres06 ~]# yum install postgis24_96.x86_64 0:2.4.5-1.rhel7 -y

Installed:
  postgis.x86_64 0:2.0.7-1.el7                                                                                                                                               

再进入数据库添加postgis插件:

[root@plat-ecloud01-db-postgres06 share]# psql -U postgres
psql (9.6.11, server 9.6.9)
Type "help" for help.

postgres=# create extension postgis;
CREATE EXTENSION

Tips

本人在下载postgis时曾使用默认postgis版本:

postgis-2.0.7-1.el7.x86_64

但安装后发现其存放postgis的脚本目录完全不对,手动将脚本迁移到正确位置后还会报错:

[root@plat-ecloud01-db-postgres06 extension]# psql -U postgres
psql (9.6.9)
Type "help" for help.

postgres=# create extension postgis;
ERROR:  could not access file "$libdir/postgis-2.0": No such file or directory

查google后得知,这是由于postgis版本不对导致的。

后将其卸载,并安装正确版本的postgis后才修复。

转载自:https://blog.csdn.net/sunbocong/article/details/84634466

You may also like...