Bird
0
0

You have a materialized view mv_sales_summary that aggregates sales data daily. You want to refresh it every hour without blocking users querying it. Which approach is best?

hard📝 Application Q8 of 15
PostgreSQL - Views and Materialized Views

You have a materialized view mv_sales_summary that aggregates sales data daily. You want to refresh it every hour without blocking users querying it. Which approach is best?

ADrop and recreate the materialized view every hour
BUse <code>REFRESH MATERIALIZED VIEW mv_sales_summary;</code> without CONCURRENTLY
CUse <code>REFRESH MATERIALIZED VIEW CONCURRENTLY mv_sales_summary;</code> scheduled hourly
DManually update the materialized view data with INSERT statements
Step-by-Step Solution
Solution:
  1. Step 1: Identify requirement for non-blocking refresh

    Users must query while refresh runs, so no blocking allowed.
  2. Step 2: Choose best refresh method

    REFRESH MATERIALIZED VIEW CONCURRENTLY allows refresh without blocking queries.
  3. Final Answer:

    Use REFRESH MATERIALIZED VIEW CONCURRENTLY mv_sales_summary; scheduled hourly -> Option C
  4. Quick Check:

    Non-blocking refresh = CONCURRENTLY option [OK]
Quick Trick: Schedule CONCURRENTLY refresh for non-blocking updates [OK]
Common Mistakes:
  • Dropping and recreating wastes resources and blocks queries
  • Using refresh without CONCURRENTLY blocks users
  • Trying manual inserts to update materialized view

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes