【问题标题】:Error when installing postgis extension to postgresql database将 postgis 扩展安装到 postgresql 数据库时出错
【发布时间】:2021-10-20 22:11:59
【问题描述】:

我在将 postgis 安装到现有数据库时遇到问题。 但出现这样的错误:

ERROR:  could not load library "/usr/local/pgsql/lib/postgis-2.0.so": libgeos_c.so.1: cannot open shared object file: No such file or directory

postgis-2.0.so 在/usr/local/pgsql/lib/postgis-2.0.so 没问题。 libgeos_c.so.1 安装在 /usr/local/lib 中。

那么,这里有什么问题呢?

任何帮助将不胜感激。

谢谢。

顺便说一句,我安装了所有这些,然后是本教程:

http://www.codingsteps.com/installing-and-configuring-postgresql-in-amazon-linux-ami/

更新

$ ldd /usr/local/lib/libgeos_c.so.1
linux-vdso.so.1 =>  (0x00007fff6f55b000)
libgeos-3.3.7.so => /usr/local/lib/libgeos-3.3.7.so (0x00007f53700d9000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f536fdd0000)
libm.so.6 => /lib64/libm.so.6 (0x00007f536fb4c000)
libc.so.6 => /lib64/libc.so.6 (0x00007f536f7c0000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f536f5ab000)
/lib64/ld-linux-x86-64.so.2 (0x00007f537068d000)

【问题讨论】:

    标签: postgresql postgis


    【解决方案1】:

    方式更容易使用 Ubuntu、Debian、Fedora、RHEL 等合理的 Linux 发行版。然后您可以根据需要使用 http://apt.postgresql.org/http://yum.postgresql.org/ 并获得所有这些东西预制且易于安装。 Amazon 的 PostgreSQL 封装是unsafe bordering on incompetent,应该避免使用。

    我怀疑当前的问题是/usr/local/lib 不在LD_LIBRARY_PATH 和/或/etc/ld.so.conf 中,所以当PostgreSQL dlopen(...)postgis-2.0.so 尝试解析libgeos_c.so.1 时,它无法找到它。

    另一种可能性是/usr/local/lib/libgeos_c.so.1 是指向不存在文件的符号链接。

    【讨论】:

    • 嘿克雷格,感谢您的回复。我刚刚尝试过export LD_LIBRARY_PATH=/usr/local/lib,但它似乎不起作用。有什么想法吗?
    • @Still.Wang 好吧,只是将 env var 导出到你的 shell 中不会有任何区别,因为它只有在你设置 postgresql 服务器的环境时才会做任何事情 i> 过程。您需要修改 postgresql 的 init 脚本或将其添加到 /etc/ld.so.conf,以便全局影响每个程序。
    • 刚刚检查了那个文件,内容是include ld.so.conf.d/*.conf /usr/local/lib
    • 对不起,我真的不是 linux 人。 :(
    • 好的,所以下一步通常是运行 ldd /usr/local/lib/libgeos_c.so.1 。查看是否有任何错误或缺少依赖项。不过,说真的,如果你“不是真正的 Linux 人”,你应该把这个虚拟机扔掉,用一个漂亮的 Ubuntu 或 Fedora VM 替换它,那里有官方的 PostgreSQL 包,包括 PostGIS,等等。你做的很艰难。
    【解决方案2】:

    如果您通过源代码安装了 postgis,可能您忘记运行 sudo ldconfig。运行这个对我有用!

    谢谢Yunwei.W,我在你分享的wiki上看到了这个!

    【讨论】:

    • 这为我节省了一天
    【解决方案3】:

    我似乎偶然遇到了类似的问题。在 Cent OS 6 上,我从 PostgreSQL YUM 存储库安装了二进制 PostgreSQL 9.3。从官方稳定版 tar 编译 GDAL 库版本 1.11.0。然后从原始 PostGIS 存储库编译 PostGIS 2.1.4dev。单元测试表明,libgdal 没有加载,因为它没有被发现。错误消息看起来类似于原始问题中的错误消息。 @Craig 提出了使用 strace 的想法。关键在于将strace 专门附加到在客户端连接到DBMS 之后创建的进程。将strace 附加到DBMS 后,让客户端请求服务器到当前数据库上的CREATE EXTENSION postgis 并查看strace 的输出。就我而言,它给出了这个:

    open("/lib64/tls/x86_64/libgdal.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/lib64/tls/x86_64", 0x7fffefb20290) = -1 ENOENT (No such file or directory)
    open("/lib64/tls/libgdal.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/lib64/tls", {st_mode=S_IFDIR|0555, st_size=4096, ...}) = 0
    open("/lib64/x86_64/libgdal.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/lib64/x86_64", 0x7fffefb20290)   = -1 ENOENT (No such file or directory)
    open("/lib64/libgdal.so.1", O_RDONLY)   = -1 ENOENT (No such file or directory)
    stat("/lib64", {st_mode=S_IFDIR|0555, st_size=12288, ...}) = 0
    open("/usr/lib64/tls/x86_64/libgdal.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/usr/lib64/tls/x86_64", 0x7fffefb20290) = -1 ENOENT (No such file or directory)
    open("/usr/lib64/tls/libgdal.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/usr/lib64/tls", {st_mode=S_IFDIR|0555, st_size=4096, ...}) = 0
    open("/usr/lib64/x86_64/libgdal.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/usr/lib64/x86_64", 0x7fffefb20290) = -1 ENOENT (No such file or directory)
    open("/usr/lib64/libgdal.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
    stat("/usr/lib64", {st_mode=S_IFDIR|0555, st_size=12288, ...}) = 0
    

    它显示 DBMS 试图在哪些特定路径中查找库。在我的情况下,库位于 /usr/local/lib/libgdal.so.1.18.0 中,带有符号链接,用于在同一目录中使用更广泛的版本。我的解决方案是将这些文件的符号链接放入/usr/lib64 目录中。

    【讨论】:

    • 你能告诉我你做了什么将所有符号链接复制到目录中,而且你似乎在 /lib64 中拥有所有符号链接,在我的情况下它在不同的目录中你建议什么为了那个原因。我有点卡在这个过程中。
    【解决方案4】:

    我已经有一段时间没有解决这个问题了,几乎忘记了我之前问过的这个问题。我发现仍然有可能遇到这个问题的人投赞成票。

    所以基本上,我发现这个问题可能是因为sudo apt-get install postgis 安装的postgis 插件没有正确安装到PostgreSQl 数据库首选的位置。我真的不是一个 linux 人来确保这一点。但似乎每次我尝试以这种方式安装postgis 时,都会出现此错误。

    因此,解决此问题的方法是,从源代码下载、构建和安装 postgis

    我关注了这个wiki。希望对某人有所帮助。

    【讨论】:

      【解决方案5】:

      /etc/ld.so.conf.d/ 应该包含 postgresql 库 dir 和 geos 库的路径。

      Amazon linux 上的 postgresql 9.6.6 示例:

      -create postgresql-pgdg-libs.conf with "/usr/lib64/pgsql96/" path
      -create libgeos.conf with "/usr/local/lib/" path 
      -check the geos library present in 
       ldconfig -v | grep geos
      - if yes compile the extension
      sudo -u postgres -- psql -c "CREATE EXTENSION postgis;"
      

      【讨论】:

        【解决方案6】:

        这个命令对我有用

        sudo ln -s /usr/lib/x86_64-linux-gnu/libgeos_c.so.1 /usr/lib/

        它基本上是指向 django 想要的位置的符号链接。默认情况下,libgeos_c.so.1 安装在/usr/lib/x86_64-linux-gnu 文件夹中

        【讨论】:

          【解决方案7】:

          如果它对未来的任何人有帮助,我也遇到了类似的问题(现在是 postgis 3.0.1),结果问题的根源是在 AWS Linux 2 上,我必须手动安装 pgxs postgres 的一部分(用于管理扩展),并且在安装过程中,./configure 命令的一部分将扩展库的路径硬编码为/usr/lib64/perl5/CORE/libperl.so 所在的位置)。这是配置命令:

          (见最后的参数)

          /usr/lib64/pgsql/pgxs/src/Makefile.global:configure_args =  '--build=x86_64-koji-linux-gnu' '--host=x86_64-koji-linux-gnu' '--program-prefix=' '--disable-dependency-tracking' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--disable-rpath' '--with-perl' '--with-tcl' '--with-tclconfig=/usr/lib64' '--with-ldap' '--with-openssl' '--with-pam' '--with-gssapi' '--with-ossp-uuid' '--with-libxml' '--with-libxslt' '--enable-nls' '--enable-dtrace' '--with-selinux' '--with-system-tzdata=/usr/share/zoneinfo' '--datadir=/usr/share/pgsql' '--with-systemd' '--with-icu' '--with-python' 'build_alias=x86_64-koji-linux-gnu' 'host_alias=x86_64-koji-linux-gnu' 'CFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -Wl,-rpath=/usr/lib64/perl5/CORE/ -L/usr/lib64/perl5/CORE/' 'LDFLAGS=-Wl,-z,relro ' 'CXXFLAGS=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches   -m64 -mtune=generic' 'PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig'
          
          /usr/lib64/pgsql/pgxs/src/Makefile.global:CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -Wl,-rpath=/usr/lib64/perl5/CORE/ -L/usr/lib64/perl5/CORE/
          

          无论如何,我最终通过@progalgo 提到strace 发现postgis 试图使用的库(在创建扩展时)位于/usr/local/lib 但没有配置LD_LIBRARY_PATH env变量会让它看起来在那里。所以我将文件从 perl 文件夹移到 /usr/local/lib,删除了 /CORE 目录,并将“CORE”符号链接到 /usr/local/lib 本身。有点hack-y,但它有效。

          【讨论】:

            猜你喜欢
            • 2014-05-08
            • 2019-12-21
            • 2015-04-28
            • 2020-05-31
            • 2020-06-25
            • 2017-01-19
            • 2011-05-27
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多