代码之家  ›  专栏  ›  技术社区  ›  Nathan Long

尝试刷新物化视图时出现错误55000“object\u not\u in\u prerequisite\u state”

  •  0
  • Nathan Long  · 技术社区  · 8 年前

    我在试着跑 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)
    

    为什么我不能同时刷新?

    1 回复  |  直到 8 年前
        1
  •  3
  •   Nathan Long    8 年前

    物化视图需要一个唯一的索引

    无法刷新物化视图 CONCURRENTLY 除非它至少有一个唯一索引,如文档中所述:

    同时

    ... 仅当物化视图上至少有一个唯一索引(仅使用列名并包括所有行)时,才允许使用此选项;也就是说,它不能索引任何表达式,也不能包含WHERE子句。

    https://www.postgresql.org/docs/9.6/static/sql-refreshmaterializedview.html