📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials PostgreSQL Essentials Materialized Views

Materialized Views

6 min read
Materialized views store query results physically like a table. Use REFRESH MATERIALIZED VIEW to update them. They are perfect for expensive aggregation queries used in dashboards where real-time data is not required.

Materialized Views

CREATE MATERIALIZED VIEW sales_summary AS
SELECT date_trunc('month', created) AS month,
       SUM(total) AS revenue
FROM orders
GROUP BY 1;

-- Refresh manually
REFRESH MATERIALIZED VIEW sales_summary;

-- Refresh concurrently (no lock)
REFRESH MATERIALIZED VIEW CONCURRENTLY sales_summary;

Materialized views store query results physically — great for heavy dashboards.