Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Materialized Views - Identifying the last refresh

I presently access a series of views and materialized views. The materialized are maintained by a third party who offers little information regarding the frequency and success of the materialization. Of late the materialized views have failed to refresh and I have sent out numerous reports with incorrect/delayed data contained within.

At present I am querying each materialized I intend to use to establish when the latest update occurred within the transactional system, if it has not been refreshed then the rest of the code does not execute, however this a lot of wasted effort and can sometimes lead to an incorrect assumption (the materialized view may have been refreshed, but there were no additional transactions made - therefore the remainder of the code does not execute) and I would prefer another method.

Is there a way to identify whether a materialized view has been refreshed using an Oracle system table? If not, does anyone have any ideas how I would do this without having to contact the third party?

like image 368
Scott Avatar asked Apr 27 '11 03:04

Scott


People also ask

What happens when materialized view is refreshed?

Refreshes a materialized view. When you create a materialized view, its contents reflect the state of the underlying database table or tables at that time. The data in the materialized view remains unchanged, even when applications make changes to the data in the underlying tables.

Are materialized views automatically refreshed?

Unlike indexes, materialized views are not automatically updated with every data change. They must explicitly be refreshed, either on every commit, on a periodically time schedule or – typically in data warehouses – at the end of an ETL job.

What is true about materialized view complete refresh?

A fast refresh requires having a materialized view log on the source tables that keeps track of all changes since the last refresh, so any new refresh only has changed (updated, new, deleted) data applied to the MV. A complete refresh does what it says: it completely refreshes all data in the MV.


2 Answers

It looks like doc_180 already answered this in the comments, I'm not sure why it didn't get added as the answer

SELECT owner, mview_name, last_refresh_date   FROM all_mviews  WHERE owner = <<user that owns the materialized view>>    AND mview_name = <<name of the materialized view>> 

If you have access to the DBA tables, you could substitute DBA_MVIEWS for ALL_MVIEWS. That would allow you to get access to information about when every materialized view was refreshed rather than just the subset of materialized views that you have access to. Of course, that's probably not a difference that is particularly important in this case.

like image 186
Justin Cave Avatar answered Sep 21 '22 04:09

Justin Cave


Unfortunately oracles default date format is YYYY-MM-DD. If you need the time just use something like this:

SELECT owner, mview_name, to_char(LAST_REFRESH_DATE, 'yyyy-mm-dd hh24:mi:ss') last_refresh_date FROM all_mviews WHERE owner = 'FOO' AND mview_name = 'MV_BAR'; 
like image 38
ptr Avatar answered Sep 21 '22 04:09

ptr