Re: How to check if a materialised view is being updated?

Philip Semanchuk <philip@americanefficient.com>

From: Philip Semanchuk <philip@americanefficient.com>
To: Jayadevan M <maymala.jayadevan@gmail.com>
Cc: "Myklebust, Bjørn Magnar" <Bjorn.Myklebust@skatteetaten.no>, "pgsql-general@postgresql.org" <pgsql-general@postgresql.org>
Date: 2021-01-19T13:40:03Z
Lists: pgsql-general

> On Jan 19, 2021, at 6:33 AM, Jayadevan M <maymala.jayadevan@gmail.com> wrote:
> 
> 
> 
> So I’m looking for a way to identify if the refresh process is finished or if it’s still running  - preferably without having to wait for timeout by querying a locked materialized view.  But by e.g. using the system tables or otherwise.
> 
>  
> 
> Can anybody suggest some pointers on how to do this?
> 
>  
> Maybe pg_stat_activity will have the refresh query?

Yes, pg_stat_activity has a query column that could be searched with the regular string matching tools, including regex if necessary. pg_stat_activity also has some other useful columns that, like query_start which can tell you how long the query has been running.

Cheers
Philip