materialized_views
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| materialized_views [2018/12/06 21:05] – created 91.177.234.129 | materialized_views [2020/05/26 12:42] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Materialized_views ====== | + | * [[https:// |
| + | * [[http:// | ||
| - | * [[https:// | + | ==== Create a view log for the master table ==== |
| - | * [[http:// | + | |
| - | + | ||
| - | =====Create a view log for the master table===== | + | |
| This is required for fast refresh | This is required for fast refresh | ||
| - | < | + | < |
| + | create materialized view log on <table> | ||
| + | / | ||
| - | ====List all materialized view logs==== | + | or... |
| - | < | + | |
| - | =====Create a simple | + | create |
| - | <code> | + | tablespace |
| - | where<br /> | + | / |
| - | Fast = update changes only< | + | </ |
| - | Complete = wipe and repopulate the mview<br /> | + | |
| - | Force = fast if possible, complete if not.<br /> | + | |
| - | <br /> | + | |
| - | ====Show all materialized views and their refresh times==== | + | |
| - | < | + | |
| - | ====Show materialized view tables and masters==== | + | === List all materialized view logs === |
| - | < | + | < |
| + | select log_owner | ||
| + | , log_table | ||
| + | from | ||
| + | / | ||
| + | </ | ||
| - | =====Show refresh jobs in dba_jobs===== | + | ==== Create a simple materialized view ==== |
| - | < | + | < |
| + | create materialized view emp_mv | ||
| + | refresh [[fast | complete | force]] | ||
| + | start with sysdate | ||
| + | next sysdate + 1/24 | ||
| + | with primary key | ||
| + | as select * from emp@dblink | ||
| + | / | ||
| + | </ | ||
| + | where\\ | ||
| + | Fast = update changes only\\ | ||
| + | Complete = wipe and repopulate the mview\\ | ||
| + | Force = fast if possible, complete if not.\\ | ||
| + | |||
| + | === Show all materialized views and their refresh times === | ||
| + | < | ||
| + | set lines 100 pages 999 | ||
| + | col last_refresh format a20 | ||
| + | select owner | ||
| + | , mview_name | ||
| + | , to_char(last_refresh_date, | ||
| + | from | ||
| + | order by owner | ||
| + | , last_refresh | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | === Show materialized view tables and masters === | ||
| + | < | ||
| + | set lines 100 | ||
| + | col mview format a40 | ||
| + | col master format a40 | ||
| + | select owner || ' | ||
| + | , master_owner || ' | ||
| + | from | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | ==== Show refresh jobs in dba_jobs ==== | ||
| + | < | ||
| + | This is useful for spotting failures | ||
| + | |||
| + | set lines 100 | ||
| + | col job format 9999 | ||
| + | col log_user format a15 | ||
| + | col last format a15 | ||
| + | col next format a15 | ||
| + | col fail format 9999 | ||
| + | col what format a20 | ||
| + | select job | ||
| + | , log_user | ||
| + | , to_char(last_date, | ||
| + | , to_char(next_date, | ||
| + | , failures fail | ||
| + | , replace(what, | ||
| + | from | ||
| + | where what like ' | ||
| + | / | ||
| + | </ | ||
| + | |||
| + | ==== Force a refresh ==== | ||
| + | All views | ||
| + | < | ||
| + | set serveroutput on | ||
| + | declare | ||
| + | l_retval number := 0; | ||
| + | begin | ||
| + | dbms_output.enable(null); | ||
| + | dbms_mview.refresh_all_mviews (l_retval,' | ||
| + | dbms_output.put_line (' | ||
| + | end; | ||
| + | / | ||
| + | </ | ||
| - | =====Force a refresh===== | ||
| Fast - uses the changes in the view log on the source side. | Fast - uses the changes in the view log on the source side. | ||
| - | < | + | < |
| + | execute dbms_mview.refresh ('< | ||
| + | </ | ||
| Complete - truncates or deletes the data (depending on other options) and rebuilds the view from scratch (remember to gather view stats afterwards). | Complete - truncates or deletes the data (depending on other options) and rebuilds the view from scratch (remember to gather view stats afterwards). | ||
| - | < | + | < |
| + | execute dbms_mview.refresh ('< | ||
| + | </ | ||
| Force - tries a fast. If this does not work, a complete will be done. | Force - tries a fast. If this does not work, a complete will be done. | ||
| - | < | + | < |
| + | execute dbms_mview.refresh ('< | ||
| + | </ | ||
| - | =====Rebuild a broken View===== | + | ==== Rebuild a broken View ==== |
| Sometimes the materialised views stop working. If the original table was modified for example (maybe index was changed or a column removed), the view will fail. | Sometimes the materialised views stop working. If the original table was modified for example (maybe index was changed or a column removed), the view will fail. | ||
| - | * On PROD | + | * On PROD |
| - | < | + | < |
| - | * On QA | + | drop materialized view log on loyalty.account |
| - | < | + | create materialized view log on loyalty.account tablespace loyalty_dl_01 nocache with primary key, sequence including new values; |
| + | create synonym snap_ltyprd.account for loyalty.account; | ||
| + | </ | ||
| + | * On QA | ||
| + | < | ||
| + | sqlplus snap_ltyprd/ | ||
| + | drop materialized view account; | ||
| + | create materialized view snap_ltyprd.account tablespace snap_ts using index tablespace snap_ts refresh fast on demand enable query rewrite as select * from account@link_loyalty_ltyprd; | ||
| + | select count(' | ||
| + | </ | ||
| Remember to refresh the view stats! | Remember to refresh the view stats! | ||
| - | < | + | < |
| + | exec dbms_stats.gather_table_stats(snap_ltyprd, | ||
| + | </ | ||
materialized_views.1544130326.txt.gz · Last modified: 2018/12/06 21:05 by 91.177.234.129
