Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of Materialized View in PostgreSQL

I am making a dashboard system feature where i have a view for a specific report, the database I'm using is PostgreSQL. I plan to turn it to a materialized view to optimize it, but it will make the dashboard's data not real time, so i plan to refresh the materialized view every time the source table's data is updated. But, after reading the documentation here: https://www.postgresql.org/docs/current/sql-refreshmaterializedview.html

It said that REFRESH MATERIALIZED VIEW just completely replaces the contents of a materialized view, thus lowering the performance when updating the base table. That made me wonder, is there actually a good use for materialized views?

like image 990
TheOne Avatar asked Oct 12 '25 16:10

TheOne


1 Answers

A materialized view is a tool that allows queries that would otherwise take too long to complete quickly, at the price of working with slightly stale data. You use it if you cannot find a better solution.

like image 113
Laurenz Albe Avatar answered Oct 15 '25 00:10

Laurenz Albe