postgresql Postgis安装:类型“几何”不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6850500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 23:02:09  来源:igfitidea点击:

Postgis installation: type "geometry" does not exist

postgresqlgeometrypostgis

提问by yetty

I am trying to create table with Postgis. I do it by this page. But when I import postgis.sql file, I get a lot of errors:

我正在尝试使用 Postgis 创建表。我是通过这个页面来做的。但是当我导入 postgis.sql 文件时,出现了很多错误:

ERROR:  type "geometry" does not exist

Does anybody know how can I fix it?

有谁知道我该如何解决?

回答by Krishna Sapkota

I had the same problem, but it was fixed by running following code

我有同样的问题,但它通过运行以下代码修复

CREATE EXTENSION postgis;

In detail,

详细,

  1. open pgAdmin
  2. select (click) your database
  3. click "SQL" icon on the bar
  4. run "CREATE EXTENSION postgis;" code
  1. 打开 pgAdmin
  2. 选择(单击)您的数据库
  3. 单击栏上的“SQL”图标
  4. 运行“创建扩展 postgis;” 代码

回答by Brendan Nee

You can do it from terminal:

您可以从终端执行此操作:

psql mydatabasename -c "CREATE EXTENSION postgis";

回答by ludwig

If the Postgis-Extension is loaded, then your SQL perhaps does not find the geometry-type because of missing search-path to the public schema.

如果加载了 Postgis-Extension,那么您的 SQL 可能由于缺少公共模式的搜索路径而找不到几何类型。

Try

尝试

SET search_path = ..., public;

SET search_path = ..., public;

in the first line of your scsript. (replace ... with the other required search-paths)

在你的脚本的第一行。(用其他所需的搜索路径替换 ...)

回答by Mike T

To get psql to stop on the first error, use -v ON_ERROR_STOP=1(which is off by default, which is why you see many errors). For example:

要让 psql 在第一个错误时停止,请使用-v ON_ERROR_STOP=1默认情况下关闭的,这就是您看到许多错误的原因)。例如:

psql -U postgres -d postgis -v ON_ERROR_STOP=1 -f postgis.sql

The actual error is something like "could not load library X", which can vary on your situation. As a guess, try this command before installing the sql script:

实际错误类似于“无法加载库 X”,这可能因您的情况而异。作为猜测,在安装 sql 脚本之前尝试此命令:

ldconfig

(you might need to prefix with sudodepending on your system). This command updates the paths to all system libraries, such as GEOS.

sudo根据您的系统,您可能需要添加前缀)。此命令更新所有系统库(例如 GEOS)的路径。

回答by Baptiste Donaux

You must enable the extension on your database.

您必须在数据库上启用扩展。

psql my_database -c "CREATE EXTENSION postgis;"

psql my_database -c "CREATE EXTENSION postgis;"

回答by Leonardo Kuffo

This error may also occur if you try to use postgis types on another schemarather than public.

如果您尝试在另一个架构上使用 postgis 类型而不是public.

If you are creating you own schema, using postgis 2.3 or higher and encounter this error, do the following as stated here:

如果您正在使用 postgis 2.3 或更高版本创建自己的架构并遇到此错误,请按照此处所述执行以下操作:

CREATE SCHEMA IF NOT EXISTS my_schema;
CREATE extension postgis;

UPDATE pg_extension 
  SET extrelocatable = TRUE 
    WHERE extname = 'postgis';

ALTER EXTENSION postgis 
  SET SCHEMA my_schema;

ALTER EXTENSION postgis 
  UPDATE TO "2.5.2next";

ALTER EXTENSION postgis 
  UPDATE TO "2.5.2";

SET search_path TO my_schema;

Then you can proceed to use postgis functinalities.

然后您可以继续使用 postgis 功能。

回答by mozboz

You also need to ensure that the user you are trying to use the postgis extension as, has access to the schema where postgis is setup (which in the tutorials I read is called 'postgis').

您还需要确保您尝试使用 postgis 扩展的用户可以访问设置 postgis 的模式(在我阅读的教程中称为“postgis”)。

I just had this error, and it was solved because I had only given a new user access to the database. In the database I'd created, I ran:

我刚刚遇到了这个错误,它已经解决了,因为我只给了一个新用户访问数据库的权限。在我创建的数据库中,我运行:

grant all on schema postgis to USERNAME; 

And this solved this error

这解决了这个错误

回答by jase81

The answers here may solve your problem, however if you already have postgis enabled on your DB, the issue may be that you are trying to restore a postgis table (with a geometry column) into a schema other than where your postgis extension is enabled. In pgAdmin you can click on the postgis extension and see which schema is specified. If you are trying to restore a table with geometry column into a different schema, you might get this error.

这里的答案可能会解决您的问题,但是如果您已经在数据库上启用了 postgis,那么问题可能在于您试图将 postgis 表(带有几何列)恢复到启用 postgis 扩展的模式之外的模式中。在 pgAdmin 中,您可以单击 postgis 扩展并查看指定的架构。如果您尝试将带有几何列的表恢复到不同的模式,您可能会收到此错误。

I resolved this by altering my postgis extension - however I'm not sure if that was necessarily the best way to do it. All I know is that it allowed me to restore the table.

我通过改变我的 postgis 扩展解决了这个问题 - 但是我不确定这是否一定是最好的方法。我所知道的是它允许我恢复表。

回答by Karolius

First make sure you have (matching to pg version: psql -V) postgis installed:

首先确保您已安装(与 pg 版本匹配:psql -V)postgis:

sudo apt install postgis postgresql-9.6-postgis-2.3

Just before tables creation add:

就在表创建之前添加:

db.engine.execute('create extension postgis') 
db.create_all()

回答by softweyr

Or...

或者...

cursor.execute('create extension postgis')

in your python program, using a current cursor from psycopg2.

在你的 python 程序中,使用来自 psycopg2 的当前光标。