Slow Complete Refresh of Materialized View in Oracle Database

The status of the materialized view with 30 million records is ‘UNUSABLE’, so a complete refresh is required to fix this problem .

The complete refresh process ran for 3 hours, then we have to kill it.

SQL>  execute dbms_mview.refresh(MVIEW1','c');



^C^C
^C^C^C^C^C^C^C

BEGIN dbms_mview.refresh('MVIEW1','c'); END;

*
ERROR at line 1:
ORA-12152: TNS:unable to send break message


Elapsed: 03:11:16.16

There are a couple of following ways to speed up this complete refresh, one of them only takes 27 minutes.

Subscribe to get access

Read more of this content when you subscribe today.

Change Materialized View Refresh Mode Makes Materialized View Unusable

The materialized view was in good status until when changes its refresh mode:

SQL>  select MVIEW_NAME,REFRESH_MODE,REFRESH_METHOD,STALENESS 
      dba_mviews 
      where mview_name='MVIEW1';

MVIEW_NAME     REFRES     REFRESH_  STALENESS  
-------------- ---------- --------- ----------
MVIEW1         COMMIT     FAST      FRESH    


SQL> alter materialized view MVIEW1 refresh fast on demand;



SQL>  select MVIEW_NAME,REFRESH_MODE,REFRESH_METHOD,STALENESS 
      dba_mviews 
      where mview_name='MVIEW1';

MVIEW_NAME     REFRES     REFRESH_  STALENESS  
-------------- ---------- --------- ------------------
MVIEW1         COMMIT     FAST      COMPILATION_ERROR 

 

SQL> alter materialized view MVIEW1 compile;

Materialized view altered.


SQL>  select MVIEW_NAME,REFRESH_MODE,REFRESH_METHOD,STALENESS 
      dba_mviews 
      where mview_name='MVIEW1';

MVIEW_NAME     REFRES     REFRESH_  STALENESS  
-------------- ---------- --------- --------------------
MVIEW1         COMMIT     FAST      UNUSABLE

It might be a bug ? not quite sure why. In this situation, the materialized view has to be refreshed completed or rebuilt.

Materialized View Refresh Group

This post demonstrates how to create and maintain a materialized view refresh group in Oracle database.

Subscribe to get access

Read more of this content when you subscribe today.

Check Last Refresh Date and Time of Oracle Materialized Views

SQL>SELECT
           OWNER,
           MVIEW_NAME,
           REFRESH_MODE,
           REFRESH_METHOD,
           TO_CHAR(LAST_REFRESH_END_TIME,'YYYYMMDD-HH24:MI:SS'),
           STALENESS 
    FROM
           DBA_MVIEWS;

“ORA-01031: insufficient privileges” from SYS User Creating Materialized Views

A client try to create a materialized view by SYS user with the following errors:

SQL> show user
USER is "SYS"

SQL> create materialized view USER1.MV_TABLE2
BUILD IMMEDIATE
REFRESH FAST ON commit
with primary key
as select * from USER2.TABLE2;


ERROR at line 6:
ORA-01031: insufficient privileges

SOLUTION

Subscribe to get access

Read more of this content when you subscribe today.