refresh-matview-non-concurrent
errorREFRESH MATERIALIZED VIEW without CONCURRENTLY
Why it's unsafe
REFRESH MATERIALIZED VIEW without CONCURRENTLY takes an ACCESS EXCLUSIVE lock and blocks all reads of the view while it rebuilds.
Safe rewrite
Use REFRESH MATERIALIZED VIEW CONCURRENTLY (requires a unique index on the matview) so reads are not blocked during the rebuild.
Example
Try it in the playground →Unsafe
REFRESH MATERIALIZED VIEW mv_sales;Safe
REFRESH MATERIALIZED VIEW CONCURRENTLY mv_sales;