Bird
0
0

After running REFRESH MATERIALIZED VIEW mv_report;, you notice the query takes a long time and blocks other queries. What could be a reason and how to fix it?

medium📝 Debug Q7 of 15
PostgreSQL - Views and Materialized Views

After running REFRESH MATERIALIZED VIEW mv_report;, you notice the query takes a long time and blocks other queries. What could be a reason and how to fix it?

AThe materialized view is corrupted; drop and recreate it
BThe database is in read-only mode; restart the server
CThe base tables are missing indexes; add indexes to speed up refresh
DThe refresh locks the view; use CONCURRENTLY option to avoid blocking
Step-by-Step Solution
Solution:
  1. Step 1: Understand locking behavior of refresh

    Standard refresh locks the materialized view, blocking other queries.
  2. Step 2: Identify solution

    Using REFRESH MATERIALIZED VIEW CONCURRENTLY avoids locking and blocking.
  3. Final Answer:

    The refresh locks the view; use CONCURRENTLY option to avoid blocking -> Option D
  4. Quick Check:

    Use CONCURRENTLY to prevent blocking = The refresh locks the view; use CONCURRENTLY option to avoid blocking [OK]
Quick Trick: Use CONCURRENTLY to refresh without blocking queries [OK]
Common Mistakes:
  • Assuming corruption causes slow refresh
  • Thinking base table indexes affect refresh locking
  • Restarting server unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes