首页 > 解决方案 > 在 MacOS 下使用 MacPorts 安装 PostgreSQL 12 / PostGIS 3.0 时,如何使用 postgis_restore.pl 脚本?

问题描述

我全新安装了 PostgreSQL 12 / PostGIS 3.0,在 MacOS (Mojave) 下使用 MacPorts 完成,我尝试使用传统脚本 postis_restore.pl 恢复启用 PostGIS 的数据库。

我首先创建了一个启用了 PostGIS 3.0 的空数据库。我的数据库转储来自带有 PostGIS 2.5 的 PosgtresSQL 9.4。它是使用 -Fc 格式完成的。

我尝试:

perl /opt/local/share/postgresql12/contrib/postgis-3.0/postgis_restore.pl /Users/me/Documents/db/dump_file.dump | psql -h localhost -U postgres target_db 2>errors.txt

我得到以下答案:

Converting /Users/me/Documents/db/dump_file.dump to ASCII on stdout...
Reading list of functions to ignore...
Writing manifest of things to read from dump file...
Writing ASCII to stdout...
ALTER TABLE
ALTER TABLE
pg_restore: error: one of -d/--dbname and -f/--file must be specified
Done.
SELECT 8500
DELETE 8500
UPDATE 0
INSERT 0 8500
DROP TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE

怎么解决 :

pg_restore: error: one of -d/--dbname and -f/--file must be specified

谢谢

标签: postgresqlpostgismacports

解决方案


在 PostgreSQL 12 中,pg_restore 的行为被更改为要求 -f 或 -d。以前,如果两者都没有指定,那么它会将其输出流式传输到 stdout,现在通过指定-f -. 之所以更改,是因为许多人对旧行为感到困惑(尽管更改本身也令人困惑)。

显然 postgis_restore.pl 从未更新以反映此更改。您应该能够找到调用 pg_restore 的位置并添加-f -到它。尽管鉴于此脚本显然从未经过测试,但我会谨慎使用它而无需进一步审查。


推荐阅读