|
Oracle Home |
|
Home > Oracle Database Administration (DBA) > Replication > Materialized views (=snapshot) |
|
Oracle 10g, 11g Database Administration (DBA): Replication |
||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Materialized views (=snapshot) |
||||||||||||||||||||||
|
A materialized view is the images of a table or view at a specific time or the replication at that table in real time. Technically, the materialized view is created as a copy of the source table which could be updated periodically with the changes done on the source table. Sometimes the changes are not applied and the materialized view is recreated (if the MV doesn't need to be refreshed often and on the source table there are many DML is better to recreate the materialized view rather then to apply the latest DML).
When a materialized view is created a new table is created. This table is refreshed regularly by a job created in the same time as the MV. However if the MV don't need to be refresh by a job, the job is not created (REFRESH ON DEMAND or REFRESH ON COMMIT are not creating a database job).
2. Create the materialized view logs (MVL)
If the materialized view (MV) will be refreshed by applying the latest changes the MVL must be created. The MVL are tables situated on the source schema which keep the latest changes. When the MV is refreshed these logs are applied on the target MV.
In this example I will show how the MVs work in the same database (in general the replications are done between 2 or more databases; in this case the DBlinks are used to access the remote/ source tables/ MV logs). In my example the source table will be EMP from SCOTT user and the MV will be created on the PAUL account.
The MVL are created on the source database/ schema:
CREATE MATERIALIZED VIEW LOG ON SCOTT.EMP; (the PK is used)
2 new table are created: MLOG$_EMP --> snapshot log for master table SCOTT.EMP RUPD$_EMP --> are created only if the base table has a PK. The rupd$_ table supports updateable materialized views, which are only possible on log tables with primary keys.
CREATE MATERIALIZED VIEW LOG ON SCOTT.EMP with ROWID; (the rowid is used)
3. Create the materialized view (MV)
MATERIALIZED VIEW MV_EMP build immediateREFRESH FAST ON COMMITAS SELECT * FROM scott.emp;Don't forget to grant "ON COMMIT REFRESH" to paul: grant ON COMMIT REFRESH to paul; (connected as sys)
A
Build Methods
Refresh Modes
Refresh Options
The following statement create a materialized view which is refreshed at every 15 minutes:
MATERIALIZED VIEW mv_emp2 BUILD IMMEDIATEREFRESH FASTSTART WITH SYSDATENEXT SYSDATE + 5/(24*60)AS SELECT * FROM scott.emp;
4. Finding the Oracle job associated with a specific materialized view
SELECT * FROM USER_JOBS WHERE WHAT like '%<mv_name>%';
SELECT * FROM USER_JOBS WHERE WHAT like '%MV_EMP2%';
5. Changing the refresh time for a particular materialized view
DBMS_REFRESH .CHANGE( name => 'PAUL.MV_EMP2',next_date => to_date('05-07-2007 23:00:00','DD-MM-YYYY HH24:MI:SS') ); commit;end; / This script will run the following script:
SYS .DBMS_JOB.CHANGE (job => job_number,what => 'dbms_refresh.refresh(''"PAUL"."MV_EMP2"'');',next_date => to_date('20/08/2007 17:00:00','dd/mm/yyyy hh24:mi:ss'), interval => 'SYSDATE + 1' ); commit;end; /
More information about this subject ( Materialized views (=snapshot) ) you can get from www.in-oracle.com
|
|
Home > Oracle Database Administration (DBA) > Replication > Materialized views (=snapshot) |
|
Different Romanian Links/ Linkuri romanesti diferite |
Disclaimer: The views expressed on this web site are my own and do not reflect the views of Oracle Corporation. You may use the information from this site only at your risk. Copyright (c) 2009-2011 Paul Catalin Tomoiu. All rights reserved.