首页 > 解决方案 > 从 Postgres 9 迁移到 13 后无法创建 postgis 扩展

问题描述

我们正在将我们的主要生产数据库从 Postgres 9.2.4 迁移到 Postgres 13.2。我们对数据库进行了 pg_dump/pg_restore 到它的新服务器,发现总共有 6 个表(99 个)似乎没有到达新位置。在尝试转储单个表然后恢复它们时,我们遇到了以下错误:

[user@server ~]$ psql -U db_user db_name < /home/pmena/tmp/missing_table_1.dump
SET
SET
SET
SET
SET
SET
SET
SET
ERROR:  type "geometry" is only a shell
LINE 2:     locationlonlat geometry,
                           ^
ERROR:  relation "db_user.missing_table_1" does not exist
ERROR:  relation "missing_table_1" does not exist
invalid command \.
ERROR:  relation "missing_table_1" does not exist
ERROR:  relation "missing_table_1" does not exist
ERROR:  relation "missing_table_1" does not exist
ERROR:  relation "missing_table_1" does not exist
ERROR:  relation "missing_table_1" does not exist
ERROR:  relation "missing_table_1" does not exist

搜索像这样的 Stack Overflow 文章指出缺少 postgis 扩展。然后我尝试删除并重新创建扩展,但偶然发现了另一个错误:

db_name=# drop extension postgis;
ERROR:  extension "postgis" does not exist
db_name=# create extension postgis;
ERROR:  relation "spatial_ref_sys" already exists

所以现在似乎 postgis 扩展的某些组件spatial_ref_sys已经存在,阻止我按照建议创建扩展。再说一次,如果 spatial_ref_sys 已经存在而没有它,那么它们是提供geometry类型的另一种方式吗?

这是我希望我不必问的问题:从 Postres 9 到 13 的跳跃是否过于雄心勃勃?我们已经在 Postgres 13 上投入了一个多月的时间,并且在尝试使用这个功能子集之前没有发现任何问题。

与往常一样,提前感谢您。

标签: postgresqlpostgis

解决方案


删除数据库,在其中重新创建它,CREATE EXTENSION postgis;然后恢复转储。从转储中恢复可能会出现错误spatial_ref_sys,但这应该没问题。


推荐阅读