PostgreSQL查看索引是否失效

PostgreSQL查看索引是否失效

  • PostgreSQL查看索引是否失效

PostgreSQL查看索引是否失效

-- PostgreSQL查看索引是否失效
SELECT trel.relname AS table_name,
       irel.relname AS index_name,
       string_agg(a.attname,',' ORDER BY c.ordinality) AS columns
  FROM pg_index AS i
  JOIN pg_class AS trel
    ON trel.oid = i.indrelid
  JOIN pg_class AS irel
    ON irel.oid = i.indexrelid
  JOIN pg_attribute AS a
    ON trel.oid = a.attrelid
  JOIN LATERAL unnest(i.indkey) WITH ORDINALITY AS c(colnum, ordinality)
    ON a.attnum = c.colnum
 WHERE not i.indisvalid
 GROUP BY i,trel.relname,irel.relname;

你可能感兴趣的:(PostgreSQL,postgresql,数据库)