Answers:
缺少空间索引的表可以通过查询系统表来找到:
SELECT g.*
FROM
(SELECT
n.nspname,
c.relname,
c.oid AS relid,
a.attname,
a.attnum
FROM pg_attribute a
INNER JOIN pg_class c ON (a.attrelid=c.oid)
INNER JOIN pg_type t ON (a.atttypid=t.oid)
INNER JOIN pg_namespace n ON (c.relnamespace=n.oid)
WHERE t.typname='geometry'
AND c.relkind='r'
) g
LEFT JOIN pg_index i ON (g.relid = i.indrelid AND g.attnum = ANY(i.indkey))
WHERE i IS NULL;
WHERE t.typname IN ('geometry', 'geography') AND t.typtype='b'
吗?参见trac.osgeo.org/gdal/ticket/6896。
t.typtype = 'b'
吗?
create table "geometry" (foo text);
给ERROR: type "geometry" already exists HINT: A relation has an associated type of the same name, so you must use a name that doesn't conflict with any existing type.
我创建了一个可以自动创建所有缺失索引的函数。“模拟”参数允许获取缺少的空间索引的列表,但不执行CREATE INDEX
参见https://gist.github.com/mdouchin/cfa0e37058bcf102ed490bc59d762042
要获取缺少索引的列表,请运行:
SELECT * FROM create_missing_spatial_indexes(True)
要创建所需的索引,请运行:
SELECT * FROM create_missing_spatial_indexes()
要么
SELECT * FROM create_missing_spatial_indexes(False)