Concept
Materialized view
View whose result is physically stored on disk and refreshed on demand, trading freshness for query speed.
A materialized view stores the result of a query as a physical table. Subsequent reads return the cached rows immediately, regardless of how expensive the underlying query was, until you REFRESH MATERIALIZED VIEW to recompute.
CREATE MATERIALIZED VIEW daily_revenue AS
SELECT date_trunc('day', created_at) AS day, sum(total) FROM orders GROUP BY 1;
REFRESH MATERIALIZED VIEW CONCURRENTLY daily_revenue;
Use materialized views for expensive aggregations that don't need to be perfectly up to date — daily reports, search indexes derived from joins, dashboards. The CONCURRENTLY option lets readers see the old result while the refresh runs, but requires a unique index on the view.
Don't confuse this with the Materialize plan node, which is a transient in-query cache, not a persisted relation.