我正在尝试运行REFRESH MATERIALIZED VIEW CONCURRENTLY recipe_search;,但是 PostgreSQL 给了我这个错误:ERROR 55000 (object_not_in_prerequisite_state): cannot refresh materialized view "public.recipe_search" concurrently。
有问题的物化视图如下所示psql:
# \d recipe_search
Materialized view "public.recipe_search"
Column | Type | Modifiers
----------+------------------------+-----------
id | integer |
title | character varying(255) |
document | tsvector |
Indexes:
"recipe_search_document_index" gin (document)
"recipe_search_title_trgm_index" gin (title gin_trgm_ops)
Run Code Online (Sandbox Code Playgroud)
为什么我不能同时刷新它?
除非物化视图CONCURRENTLY至少具有一个唯一索引,否则无法刷新,如文档中所述:
同时
...仅当物化视图上至少有一个 UNIQUE 索引且仅使用列名并包含所有行时才允许使用此选项;也就是说,它不能对任何表达式建立索引,也不能包含 WHERE 子句。
https://www.postgresql.org/docs/9.6/static/sql-refreshmaterializedview.html