We have seen Discussion Series 1 of materialized view concepts and we know how to create materialized view and also what each clause of Mview creation mean.
In this article we will see all backend tables that can be accessed to check the details of materialized view.
We will begin with identifying materialized view
DBA_SNAPSHOTS (On MView site)
Most important table for checking MView info is DBA_SNAPSHOTS.
We need to query this table on snapshot site (where MView is created)
SQL>select name, table_name, MASTER, MASTER_LINK, REFRESH_METHOD, UPDATABLE , LAST_REFRESH, STATUS, PREBUILT, REFRESH_MODE from dba_snapshots where name = 'T_REP'; NAME TABLE_NAME MASTER MASTER_LINK REFRESH_MET UPD LAST_REFRESH STATUS PRE REFRESH_ ---------- ---------- -------------------- ------------------------------ ----------- --- ---------------- ------- --- -------- T_REP T_REP T @"DB1.AMAZON" PRIMARY KEY NO 2012-10-13:22:26 UNKNOWN YES DEMAND
DBA_REFRESH_CHILDREN (On Mview Site)
we can group multiple materialized views into a group and refresh all materialized view all at once.
This can be done by creating a refresh group.
You can see all steps to create refresh group at http://docs.oracle.com/cd/B28359_01/server.111/b28327/rarmviewgroup.htm
Once you create refresh group and add MView to it, you can see the info in MVIEW_REFRESH_GROUPS table
BEGIN DBMS_REFRESH.MAKE ( name => 'TEST_REF_GROP', list => '', next_date => SYSDATE, interval => 'SYSDATE + 1/24'); END; / BEGIN DBMS_REFRESH.ADD ( name => 'TEST_REF_GROP', list => 'T_REP', lax => FALSE ); END; / SQL>select name, RNAME, REFGROUP, INTERVAL, TYPE from dba_refresh_children where name = 'T_REP'; NAME RNAME REFGROUP INTERVAL TYPE ------------------------------ ------------------------------ ---------- ------------------------------ ------------------------------ T_REP TEST_REF_GROP 3693 SYSDATE + 1/24 SNAPSHOT SQL>
DBA_SNAPSHOT_LOGS (On Master site):
If we want to check information about MLOG table, we can view this table.
SQL>select master, LOG_TABLE, ROWIDS, PRIMARY_KEY, SNAPSHOT_ID, CURRENT_SNAPSHOTS from dba_snapshot_logs where master = 'T'; MASTER LOG_TABLE ROW PRI SNAPSHOT_ID CURRENT_SNAPSHOT ------------------------------ ------------------------------ --- --- ----------- ---------------- T MLOG$_T NO YES 15119 2012-10-13:22:26
Since this is primary key based MLOG, we can see YES for primary key column. CURRENT_SNAPSHOT gives when was this last refreshed. This is same as LAST_REFRESH column in DBA_SNAPSHOTS
DBA_REGISTERED_SNAPSHOTS (On Master site):
To Check how many sites are registered for 1 master table, we can query DBA_REGISTERED_SNAPSHOTS
This table has a column called name which is basically the name of Mview on MVIEW site. Since each MVIEW site can have a different name we cannot compare this column to get list of sites registered for 1 master table.
But we don’t have any master column in this table so we join this table with DBA_SNAPSHOT_LOGS to get list of sites which are registered for a master table
SQL>select a.master, b.name, b.snapshot_site from dba_snapshot_logs a, dba_registered_snapshots b 2 where a.snapshot_id = b.snapshot_id 3 and a.master = 'T'; MASTER NAME SNAPSHOT_SITE ------------------------------ ------------------------------ ------------------------------ T T_REP DB1.AMAZON
To check which snapshots has delay
We can use following query to check which snapshots has refresh delay in mins
select a.master, b.name, b.snapshot_site, (sysdate - a.CURRENT_SNAPSHOTS)*24*60 "delay Mins" from dba_snapshot_logs a, dba_registered_snapshots b where a.snapshot_id = b.snapshot_id and (sysdate - a.CURRENT_SNAPSHOTS)*24*60 > &delay;
This will ask for delay and you can enter delay in mins.
After that this will list down all snapshots which are having delay more than what you entered.
Example, if you want to list down all snapshots having delay of more than 10 mins, you need to enter 10.
x$knstmvr
This is another internal table which can be used to check the progress of snapshots.
Columns in this table is self understood.
Following query will provide you the details of snapshot progress
column mvowner format a10 Column mvname format a30 column refmode format a8 column refstate format a12 column inserts format 99999999 column updates format 999999999 column deletes format 999999999 column event format a30 column spid format a6 select currmvowner_knstmvr mvowner, currmvname_knstmvr mvname, decode( reftype_knstmvr, 0, 'FAST', 1, 'FAST', 2, 'COMPLETE', REFTYPE_KNSTMVR ) refmode, decode(groupstate_knstmvr, 1, 'SETUP', 2, 'INSTANTIATE',3, 'WRAPUP', 'UNKNOWN' ) refstate, total_inserts_knstmvr inserts, total_updates_knstmvr updates, total_deletes_knstmvr deletes, b.spid,c.event from x$knstmvr X, v$session a, v$process b, v$session_wait c WHERE type_knst=6 and a.paddr = b.addr and a.sid = c.sid and x.SID_KNST = a.sid and x.SERIAL_KNST = a.serial#;
In the next article about MView discussion series we will discuss about MLOG table and some internal details about fast refresh and how it works.
Hope this helps !!
Filed under: Oracle Database 10g, Oracle Database 11g Tagged: materialized view, mview, snapshot Image may be NSFW.
Clik here to view.
Clik here to view.
