Search code examples
sqlmaterialized-viewscockroachdb

Fetch last Refresh time of Materialized View in CockroachDB


In CockroachDB v20.2, one can retrieve a list of Materialized Views using:

> SELECT * FROM pg_catalog.pg_matviews;
  schemaname | matviewname | matviewowner | tablespace | hasindexes | ispopulated | definition
----------------------------------------------------------------------------------------------------
  public     | VIEWNAME    | root         | NULL       |   false    |    true     | VIEWDEFINITION

From here, how can we find when this View was last Refreshed?


Solution

  • This information isn't available from the internal tables, as far as I know. I don't think PostgreSQL has it either.

    A workaround could be to define your materialized view with an additional timestamp column, like:

    create materialized view my_view as select col, now() as last_updated from tab;
    

    The downside of this is that every row in the view will have this column and will use the extra disk space.