Refresh a materialized view automatically using a rule or notify

后端 未结 2 1000
盖世英雄少女心
盖世英雄少女心 2020-11-27 11:14

I have a materialized view on a PostgreSQL 9.3 database which seldom changes (about twice a day). But when it does, I\'d like to update its data promptly.

Here is wha

2条回答
  •  粉色の甜心
    2020-11-27 11:28

    PostgreSQL 9.4 added REFRESH CONCURRENTLY to Materialized Views.

    This may be what you're looking for when you describe trying to setup an asynchronous update of the materialized view.

    Users selecting from the materialized view will see incorrect data until the refresh finishes, but in many scenarios that use a materialized view, this is an acceptable tradeoff.

    Use a statement level trigger that watches the underlying tables for any changes and then refreshes the materialized view concurrently.

提交回复
热议问题