升级 postgres 数据库文件失败 "could not access file $libdir/postgis-2.5: No such file or directory"

Upgrading postgres database files fail with "could not access file $libdir/postgis-2.5: No such file or directory"

我正在研究 OSX 并通过 Homebrew 安装了 postgres。我刚刚将 Postgres 从 v11 升级到 v13。现在我尝试更新数据库文件:

brew postgresql-upgrade-database

这失败了,查看日志,错误是:

pg_dump: error: query failed: ERROR:  could not access file "$libdir/postgis-2.5": No such file or directory

如果我这样做 brew info postgis 那么我会看到:

% brew info postgis
postgis: stable 3.0.2 (bottled), HEAD
Adds support for geographic objects to PostgreSQL
https://postgis.net/
/usr/local/Cellar/postgis/3.0.2_1 (435 files, 29.7MB) *
  Poured from bottle on 2020-11-12 at 23:15:12
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/postgis.rb
License: GPL-2.0-or-later
==> Dependencies
Build: gpp ✘, pkg-config ✔
Required: gdal ✔, geos ✔, json-c ✔, pcre ✔, postgresql ✔, proj ✔, protobuf-c ✔, sfcgal ✔
==> Options
--HEAD
    Install HEAD version
==> Analytics
install: 11,064 (30 days), 26,959 (90 days), 80,033 (365 days)
install-on-request: 10,946 (30 days), 26,628 (90 days), 78,351 (365 days)
build-error: 0 (30 days)

所以我猜 Postgis 3.0.2 是作为升级过程的一部分安装的,pg_dump(数据库文件升级需要)找不到 Postgis 2.5。

我该怎么办?我想我可以暂时将 Postgis 2.5 重新安装到 $libdir - 但是如何?

pg_config --pkglibdir 表明 $libdir/usr/local/lib/postgresql。如果我列出该目录中的文件,我可以看到它包含 postgis-3.so,但不包含 postgis-2.5.so

注意:我目前也无法使用 psql 访问 postgres - 我看到了可怕的 psql: error: could not connect to server: could not connect to server: No such file or directory。但是,brew services list 告诉我 postgresql 是 运行。

升级 PostGIS 并不是那么简单(请参阅文档),并且通过使用此发行版的自动升级,您可能会搞砸您的安装。

对您的 PostgreSQL 数据目录进行完整备份,然后卸载 PostgreSQL v13,重新安装 v11 和 PostGIS 2.5,看看您是否可以让数据库再次运行。

然后按照 PostGIS 手册中的升级程序进行操作。

用户 wiki 上有一个 compatibility/support 矩阵链接到 PostGIS 站点,这似乎表明从 Postgres v13 开始,PostGIS 的最低版本是 v3.0

如果您出于某种原因坚持使用 PostGIS v2.5,Postgres V12 看起来是您最好的选择。

如果您还没有卸载错误版本的 Postgis:

brew remove postgis

先到最后2.5版本的Postgis公式看这里:

https://raw.githubusercontent.com/Homebrew/homebrew-core/bca96164362bfa3c42b4d403be4eb3847797424f/Formula/postgis.rb

复制该代码。

将此粘贴到您计算机上的自制 Postgis 公式上:

pbpaste > $(find $(brew --repository) -name postgis.rb)

然后使用此公式再次安装 Postgis:

brew install postgis

固定 Postgis 以防止意外升级:

brew pin postgis

那应该为您提供正确版本的 Postgis。