简体   繁体   English

获取物化视图的约束和索引

[英]Get constraints and indexes on materialized views

Query to get all indexes and all constraints on all materialized views in Postgres. 查询以获取Postgres中所有物化视图的所有索引和所有约束。 The below query only returns indexes on tables. 以下查询仅返回表的索引。

SELECT indexname, indexdef 
FROM pg_indexes 
WHERE schemaname = 'public' AND tablename = 'table'

The view pg_indexes provides access to useful information about each index in the database (also indexes on materialized views). 视图pg_indexes提供对数据库中每个索引的有用信息的访问(也包括物化视图上的索引)。 You can lookup pg_class to filter out only materialized views ( relkind = 'm' ): 您可以查找pg_class以仅过滤relkind = 'm'化视图( relkind = 'm' ):

select i.*
from pg_indexes i
join pg_class c
    on schemaname = relnamespace::regnamespace::text 
    and tablename = relname
where relkind = 'm'

 schemaname | tablename |    indexname    | tablespace |                             indexdef                             
------------+-----------+-----------------+------------+------------------------------------------------------------------
 public     | my_view   | my_view_id_idx  |            | CREATE UNIQUE INDEX my_view_id_idx ON my_view USING btree (id)
 public     | sen_view  | sen_view_id_idx |            | CREATE UNIQUE INDEX sen_view_id_idx ON sen_view USING btree (id)
(2 rows)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM