如何确定 postgres 数据库是否包含 GiST 索引以及什么类型?

use*_*276 2 postgresql postgresql-9.2 gist-index

有没有办法轻松检查 PostgreSQL 数据库是否有任何 GiST 索引以及它们是什么类型?

Nei*_*gan 5

每当您需要通过代码检查数据库的结构时,请始终考虑“我应该查看information_schemapg_catalog”。information_schema包含标准化模式(66 个视图),而pg_catalog特定于 PostgreSQL,但包含更多信息(97 个表或视图)。

select 
  * 
from
  pg_catalog.pg_indexes 
where 
  indexdef ~* '\ygist\y'
Run Code Online (Sandbox Code Playgroud)

将向您展示所有要点索引及其表、名称和定义。

~* 表示匹配正则表达式,不区分大小写。

\y 表示词边界,因此它会在该列中找到 'gist' 而不是 'logistics'