REFRESH MATERIALIZED VIEW
的官方Postgresql 9.3文档尚未详细描述.
这个blog的引用:
materialized views in Postgres 9.3 have a severe limitation consisting in using an exclusive lock when refreshing it. This basically blocks any attempts to read a materialized view while it is being refreshed with new data from its parent relations
来自mailing list的帖子的另一个引用:
if I understand things correctly REFRESH MATERIALIZED VIEW locks the
materialized view with an AccessExclusiveLock even if the view already
contains data.
我的问题:以下序列是否正确:
>查询正在访问物化视图
>作业执行REFRESH MATERIALIZED VIEW.它会锁定视图,并等待所有使用matview运行的查询完成
> matview正在开始刷新;如果matview上有索引,则会同时更新(因此在一个事务中完成刷新)
>使用matview查询等待刷新完成.如果这需要太长时间,则会出现类似“等待锁定超时错误”的情况.
>刷新完成,锁定被删除
>一直在等待matview的查询继续
以下是发行说明中的更多信息:https://wiki.postgresql.org/wiki/What%27s_new_in_PostgreSQL_9.4#REFRESH_MATERIALIZED_VIEW_CONCURRENTLY