如何在 postgresql 中强制删除索引关系?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18580590/
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-11 00:23:13  来源:igfitidea点击:

How to force drop index relation in postgresql?

postgresqlpostgispostgresql-9.2

提问by kentr

In PostgreSQL 9.2 / PostGIS 2.0.2 I had an index on a spatial column, created with

在 PostgreSQL 9.2 / PostGIS 2.0.2 中,我在空间列上有一个索引,它是用

CREATE INDEX tiger_data_sld_the_geom_gist ON tiger_data.sld USING gist(the_geom);

Subsequently dropped the index with

随后下降了指数

DROP INDEX tiger_data_sld_the_geom_gist;

But now, when I try to recreate, I get this error:

但是现在,当我尝试重新创建时,出现此错误:

#  CREATE INDEX tiger_data_sld_the_geom_gist ON tiger_data.sld USING gist(the_geom);
ERROR:  relation "tiger_data_sld_the_geom_gist" already exists

Dropping again doesn't work. It says that the index doesn't exist:

再次删除不起作用。它说该索引不存在:

# DROP INDEX tiger_data_sld_the_geom_gist;
ERROR:  index "tiger_data_sld_the_geom_gist" does not exist

I haven't found the relation "tiger_data_sld_the_geom_gist" in any list of database objects, have tried DROP TABLE, and searched around for solutions.

我还没有在任何数据库对象列表中找到关系“tiger_data_sld_the_geom_gist”,尝试过 DROP TABLE,并四处寻找解决方案。

What is this mystery relation "tiger_data_sld_the_geom_gist", and how do I remove it so that I can create the index?

这个神秘关系“tiger_data_sld_the_geom_gist”是什么,如何删除它以便创建索引?

Edit:

编辑:

Also have tried restarting the server, and dumping / dropping / reloading the table (dropped with CASCADE).

还尝试重新启动服务器,并转储/删除/重新加载表(使用 CASCADE 删除)。

回答by MatheusOl

Unless you are setting the search_pathGUC to (or at least including) the tiger_dataschema, you need to add the schema to the index name to issue the DROP INDEX(I'd use it in any case for safety):

除非您将search_pathGUC设置为(或至少包括)tiger_data架构,否则您需要将架构添加到索引名称以发出DROP INDEX(为了安全起见,我会在任何情况下使用它):

DROP INDEX tiger_data.tiger_data_sld_the_geom_gist;

That's because the index always go to the same schema of the table it belongs to. If the above doesn't solve your problem, you can check if this relation name exists and on each schema it is in with the following:

那是因为索引总是转到它所属表的相同模式。如果以上没有解决您的问题,您可以检查此关系名称是否存在以及在每个模式中它是否包含以下内容:

SELECT r.relname, r.relkind, n.nspname
FROM pg_class r INNER JOIN pg_namespace n ON r.relnamespace = n.oid
WHERE r.relname = 'tiger_data_sld_the_geom_gist';

It will return the kind (ifor indexes, rfor tables, Sfor sequences and vfor views) of any relation that has the name tiger_data_sld_the_geom_gistand name of the schema it belongs to.

它将返回具有其所属模式的名称和名称的任何关系的种类(i对于索引、r表、S序列和v视图)tiger_data_sld_the_geom_gist

回答by kentr

Though not particularly efficient, this appears to have done the trick:

虽然不是特别有效,但这似乎已经成功了:

  1. Dump the table with pg_dump.
  2. Drop the table.
  3. Dump the database with pg_dump.
  4. Drop the database.
  5. Recreate the database and reload from dump files.
  1. 使用 pg_dump 转储表。
  2. 放下桌子。
  3. 使用 pg_dump 转储数据库。
  4. 删除数据库。
  5. 重新创建数据库并从转储文件重新加载。