What is a materialized view?
A materialized view stores the precomputed result of a query, making some reads faster at the cost of extra storage and the periodic work of keeping it current.
A materialized view is the stored result of a query, a request for data from a database. Anyone who queries the view reads the saved rows instead of rerunning the same calculation every time. For example, sales totals by day and salesperson can be prepared before anyone opens a report. The potential benefit is faster reads; the cost includes extra storage, the work of refreshing the result, and the risk that the result lags behind the latest changes. A regular view, by contrast, stores the query definition without saving its result: in PostgreSQL, the query runs when the view is used. The PostgreSQL documentation describes a materialized view as a persistent result that can be queried like a table and regenerated from the original query. Whether one pays off depends on actual read volume, how often the data changes, and the acceptable lag.
See also: Query execution planA query execution plan describes the operations a database chooses to answer a query, helping teams investigate the time and resources an actual run consumes.
The trade-off: saved compute versus lost freshness
Depending on what the system supports, a refresh recomputes the result or maintains it. In PostgreSQL, the refresh command replaces the entire contents by running the saved query. Other methods studied in research on view maintenance share calculations across views to reduce total work. So do not assume every platform updates only changed rows or refreshes automatically.
A refresh schedule does not guarantee freshness: any run can be slow or fail. Track when the source data arrived and when the calculation finished, and decide what happens if the result goes stale. The query execution plan, the route the database chooses to process a query, helps pinpoint where the work concentrates.
An enterprise example
A company prepares a daily sales report by region and salesperson. Its data mart, a collection of data focused on one business domain, fields many queries for the same summary. A materialized view can store the calculated totals; an overnight refresh makes them available for the morning report. The PostgreSQL documentation presents a similar example for historical sales, excluding the incomplete current day.
If a manager needs to see an order as soon as it is recorded, the overnight summary is not enough. That calls for reading current data directly, or another approach that stays within the agreed lag. The report should show its coverage period and the outcome of the last refresh, so decision makers can recognize data that is no longer fit for use.
Why it matters for decision makers
Before buying or deploying a system, ask the vendor whether refresh blocks reads and who detects a refresh failure. In PostgreSQL, the CONCURRENTLY option lets reads continue, but requires an already populated view and a unique index (a structure that tells rows apart) defined only on plain columns, with no row filter. When many rows change, a refresh without this option tends to use fewer resources and finish sooner, but can block reads. Only one refresh can run per view at a time. Measuring the actual workload and agreeing on a maximum lag let you weigh read savings against maintenance cost.
Frequently asked questions
Related terms
- Query execution planA query execution plan describes the operations a database chooses to answer a query, helping teams investigate the time and resources an actual run consumes.
- Data martA subset of the data warehouse dedicated to a single department or domain, built to answer specific questions faster.
- Star schemaA star schema organizes data for analysis into a central fact table, which holds the measurements, and into dimension tables that describe their context.
If it touches your company's data, getting that data in order is the first thing I do.
See Data Foundations