List materialized views in PostgreSQL database

Query below lists all materialized views, with their definition, in PostgreSQL database

Query

select schemaname as schema_name,
       matviewname as view_name,
       matviewowner as owner,
       ispopulated as is_populated,
       definition
from pg_matviews
order by schema_name,
         view_name;

Columns

  • schema_name - schema name
  • view_name - materialized view name
  • owner - name of materialized view's owner
  • is_populated - indicate if materialized view is currently populated (false means that view is unscannable and cannot be queried until REFRESH MATERIALIZED VIEW is used)
  • definition - materialized view script - select statement only

Rows

  • One row represents one materialized view in a database
  • Scope of rows: all materialized views, with their definition, in PostgreSQL database
  • Ordered by schema name, materialized view name

Sample results

You can also find materialized views using pgAdmin 4. Screen below show how to do it.