Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL materialized views

I finished my course on Oracle databases and have been playing with it since sometime. One of my friends told me that PostgreSQL is a very good database management system which has object oriented capabilities.

On an Oracle database, it is a straightforward and easy process to create materialized views. BUT despite of having heard that PostgreSQL supports materialized views from few people, I am unable to figure out how to do that.

Please advise.

like image 740
user1232564 Avatar asked Feb 25 '12 13:02

user1232564


People also ask

What is materialized views in PostgreSQL?

A “materialized view” is a database object which stores the result of a precalculated database query and makes it easy to refresh this result as needed. Materialized views are an integral feature of pretty much all advanced database systems.

How materialized view refresh works Postgres?

Parameters. Refresh the materialized view without locking out concurrent selects on the materialized view. Without this option a refresh which affects a lot of rows will tend to use fewer resources and complete more quickly, but could block other connections which are trying to read from the materialized view.

Why use materialized view instead of a view?

A materialized view is much more efficient at executing queries. The data is physically saved at a specific point in time. You don't need to re-read all the data associated with a query every single time. The drawback is that you have to make sure to view the most recent data.


2 Answers

For PostgreSQL version 9.2 and below, read the following article on how to create materialized views by using functions and triggers.

  • http://tech.jonathangardner.net/wiki/PostgreSQL/Materialized_Views

Since version 9.3, materialized views are natively supported:

For more information on this topic, please refer to the following articles on PostgreSQL documentation:

  • http://www.postgresql.org/docs/devel/static/sql-creatematerializedview.html
  • http://www.postgresql.org/docs/devel/static/rules-materializedviews.html
like image 80
Nick Binnet Avatar answered Sep 23 '22 02:09

Nick Binnet


There's no native support for materialized views in postgres.

You could try to emulate them with triggers/stored procedures as described in this article.

like image 33
soulcheck Avatar answered Sep 23 '22 02:09

soulcheck