If you want to get a bit fancy you can use the Oracle scheduler to execute the MV refresh. The benefit of this is that you can make the call to the scheduler such that it immediately returns control to the ETL job without waiting for the refresh to complete. This is a fire-and-forget type call.
I wrote a module like this for a client. It worked so well for materialized view refreshes that we started to use it for gathering database statistics.
Replying to this post as I am facing a new Problem now.
Somehow the MV logs are not getting refreshed when I use DI to refresh MV’s.
Dont know what wrong I am doing.
Here is what I am doing.
A DI Job to load data into Target Table. (this is a Simple Field to Field Map with a where clause on Date).
A Script after the DF to Refresh MV’s.
Things Look fine when I execute the JOB.
However when I comment the code to refresh MV’s , somehow the MV log’s which should be populated in case of changes on the base table are not getting refreshed. When I try it manually on the Database, It works fine. But with DI job somehow I am facing this issue.
Its a Materialized View log which Is required in order to have a Fast refresh on materialized View.This Log is created on the Base Table.
Syntax :-
CREATE MATERIALIZED VIEW LOG ON edw_hr_stg.test_recovery2 with primary key;
Now any Update/Delete/Insert on the base Table will automatically populate the Log table with Primary key of the Base table and type of operation performed on it.
The whole flow (Job) is pretty Simple. (A Field to Field mapping).
The confusing thing is that when I execute this Job in DEBUG mode, things go fine and I can see my MV being changed Accordingly.
However the Normal execution of the Job causes problems.
FYI :- Syntax to create MV
CREATE MATERIALIZED VIEW EDW_HR_STG.MY_MV
REFRESH FAST ON DEMAND
WITH PRIMARY KEY
AS SELECT * FROM EDW_HR_STG.TEST_RECOVERY2
Syntax to refresh this MV via DI
:-
sql(‘DS_EDW_HR_STG’,‘begin DBMS_MVIEW.REFRESH (list=>‘my_MV’,method=>‘F’); end;’);
Ya even If debugger was Slower and refresh Took time, it almost completed in 15 seconds and the data was reflected.
Same Normal mode gets completed in like 5 seconds and I waited for almost 10 minutes to see if MV is taking time to refresh. (Which obviously was not the case as its wokring fine now).
Anyways, Thanks for you help all.
@Ganesh, in case you find that Post, please let us know about the same.
I am not sure If I can replicate that issue.
Now I have 2 Jobs which refresh the MV and everything is working Fine.
(Irrespective of refreshing MV from DI or Not).
Next Time If I encounter this Issue, I will save the ATL, That way I hope we may be able to replicate it whenever we want.