2026-03-12 21:01:38
This commit is contained in:
70
materialized_views/mw01.txt
Normal file
70
materialized_views/mw01.txt
Normal file
@@ -0,0 +1,70 @@
|
||||
create pluggable database NIHILUS admin user NIHILUS$OWNER identified by secret;
|
||||
alter pluggable database NIHILUS open;
|
||||
alter pluggable database NIHILUS save state;
|
||||
|
||||
orapwd file=orapwSITHPRD password="ad420e57a205c9a7d80d!"
|
||||
|
||||
alias NIHILUS='rlwrap sqlplus adm/"secret"@bakura:1521/NIHILUS as sysdba'
|
||||
|
||||
alter session set container=NIHILUS;
|
||||
|
||||
create user DEMO identified by secret;
|
||||
grant connect, resource to DEMO;
|
||||
grant create materialized view to DEMO;
|
||||
grant create view to DEMO;
|
||||
grant unlimited tablespace to DEMO;
|
||||
|
||||
alias DEMO='rlwrap sqlplus DEMO/"secret"@bakura:1521/NIHILUS'
|
||||
|
||||
create table DEMO as
|
||||
select 0 seq,current_timestamp now
|
||||
from
|
||||
xmltable('1 to 1000');
|
||||
|
||||
|
||||
-- infinite_update.sql
|
||||
whenever sqlerror exit failure
|
||||
begin
|
||||
loop
|
||||
update demo set seq=seq+1,now=current_timestamp where rownum=1;
|
||||
commit;
|
||||
dbms_session.sleep(1);
|
||||
end loop;
|
||||
end;
|
||||
/
|
||||
|
||||
|
||||
select max(seq),max(now) from DEMO.DEMO;
|
||||
create materialized view DEMOMV1 as select * from DEMO;
|
||||
create materialized view DEMOMV2 as select * from DEMO;
|
||||
|
||||
create view V as
|
||||
select 'DEMOMV1' source,seq,now from DEMOMV1
|
||||
union all
|
||||
select 'DEMOMV2' source,seq,now from DEMOMV2
|
||||
union all
|
||||
select 'DEMO' source,seq,now from DEMO;
|
||||
|
||||
set lines 256
|
||||
col maxseq for 999999999
|
||||
col maxnow for a50
|
||||
|
||||
select source,max(seq) maxseq,max(now) maxnow from V group by source;
|
||||
|
||||
|
||||
exec dbms_refresh.make('DEMO.DEMORGROUP', list=>'DEMOMV1,DEMOMV2', next_date=>null, interval=>'null');
|
||||
|
||||
exec dbms_refresh.refresh('DEMO.DEMORGROUP');
|
||||
|
||||
-- we can index and gather stats on materialized views
|
||||
create index IMV1 on DEMOMV1(seq);
|
||||
create index IMV2 on DEMOMV2(now);
|
||||
|
||||
exec dbms_stats.gather_table_stats(user,'DEMOMV1', method_opt=>'for all columns size SKEWONLY');
|
||||
exec dbms_stats.gather_table_stats(user,'DEMOMV2', method_opt=>'for all columns size AUTO');
|
||||
|
||||
alter table DEMO add constraint PK_DEMO primary key (NOW);
|
||||
|
||||
create materialized view log on DEMO.DEMO
|
||||
including new values;
|
||||
|
||||
127
materialized_views/mw02.txt
Normal file
127
materialized_views/mw02.txt
Normal file
@@ -0,0 +1,127 @@
|
||||
alias DEMO='rlwrap sqlplus DEMO/"secret"@bakura:1521/NIHILUS'
|
||||
|
||||
drop table T1 purge;
|
||||
create table T1 (
|
||||
id number generated always as identity,
|
||||
n1 number(1),
|
||||
c1 varchar2(10),
|
||||
d1 DATE
|
||||
);
|
||||
|
||||
alter table T1 add constraint T1_PK primary key (ID);
|
||||
|
||||
|
||||
-- infinite_update2.sql
|
||||
whenever sqlerror exit failure
|
||||
declare
|
||||
i NUMBER;
|
||||
begin
|
||||
i:=0;
|
||||
loop
|
||||
i:=i+1;
|
||||
insert into T1(n1,c1,d1) values(mod(i,3),DBMS_RANDOM.string('a',10),sysdate);
|
||||
commit;
|
||||
dbms_session.sleep(1);
|
||||
end loop;
|
||||
end;
|
||||
/
|
||||
|
||||
|
||||
drop materialized view MW0;
|
||||
drop materialized view MW1;
|
||||
drop materialized view MW2;
|
||||
|
||||
create materialized view MW0 as select * from T1 where n1=0;
|
||||
create materialized view MW1 as select * from T1 where n1=1;
|
||||
create materialized view MW2 as select * from T1 where n1=2;
|
||||
|
||||
|
||||
alter session set NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS';
|
||||
select max(d1) from MW0;
|
||||
select max(d1) from MW1;
|
||||
select max(d1) from MW2;
|
||||
|
||||
create materialized view log on T1 with primary key including new values;
|
||||
|
||||
set lines 256
|
||||
|
||||
col log_table for a30
|
||||
col log_trigger for a30
|
||||
col primary_key for a3 head PK
|
||||
|
||||
select log_table,log_trigger,primary_key from dba_mview_logs where log_owner='DEMO' and MASTER='T1';
|
||||
|
||||
|
||||
-- on snap "server" site
|
||||
|
||||
set lines 256
|
||||
|
||||
col owner for a15
|
||||
col name for a25
|
||||
col master_owner for a15
|
||||
col master for a25
|
||||
col master_link for a25
|
||||
col refresh_method for a15
|
||||
col type for a10
|
||||
col status for a7
|
||||
col snaptime for a20
|
||||
|
||||
select
|
||||
snap.owner
|
||||
,snap.name
|
||||
,snap.snapid
|
||||
,snap.status
|
||||
,slog.snaptime
|
||||
,snap.master_owner
|
||||
,snap.master
|
||||
,snap.refresh_method
|
||||
,snap.type
|
||||
,snap.master_link
|
||||
from
|
||||
sys.slog$ slog
|
||||
join dba_snapshots snap on slog.snapid=snap.snapid
|
||||
where slog.mowner='DEMO' and slog.master='T1';
|
||||
|
||||
|
||||
col snapname for a30
|
||||
col snapsite for a30
|
||||
col snaptime for a30
|
||||
|
||||
select
|
||||
r.name snapname, snapid, nvl(r.snapshot_site, 'not registered') snapsite, snaptime
|
||||
from
|
||||
sys.slog$ s, dba_registered_snapshots r
|
||||
where
|
||||
s.snapid=r.snapshot_id(+) and mowner='DEMO' and master='T1';
|
||||
|
||||
|
||||
exec dbms_mview.refresh('MW0');
|
||||
exec dbms_mview.refresh('MW1');
|
||||
exec dbms_mview.refresh('MW2');
|
||||
|
||||
-- point of view of snap "client"
|
||||
select last_refresh_date,sysdate from dba_mviews where mview_name='MW0';
|
||||
|
||||
-- point of view of snap "server"
|
||||
select sysdate,last_refresh from dba_snapshots where name='MW0';
|
||||
|
||||
|
||||
select log_table from dba_mview_logs where master='T1';
|
||||
|
||||
select count(*) from DEMO.MLOG$_T1;
|
||||
|
||||
|
||||
exec dbms_refresh.make('MWGROUP0', list=>'MW0,MW1', next_date=>null, interval=>'null',parallelism=>2);
|
||||
|
||||
exec dbms_refresh.refresh('MWGROUP0');
|
||||
|
||||
|
||||
-- https://www.oracleplsqltr.com/2021/03/14/how-to-unregister-materialized-view-from-source-db/
|
||||
|
||||
exec dbms_mview.unregister_mview(mviewowner=>'DEMO',mviewname=>'MW2',mviewsite=>'NIHILUS');
|
||||
exec dbms_mview.purge_mview_from_log(mview_id=>9);
|
||||
|
||||
select segment_name,bytes/1024 Kb from dba_segments where segment_name='MLOG$_T1';
|
||||
|
||||
|
||||
|
||||
85
materialized_views/mw03.txt
Normal file
85
materialized_views/mw03.txt
Normal file
@@ -0,0 +1,85 @@
|
||||
-- setup PDB
|
||||
------------
|
||||
|
||||
orapwd file=orapwSITHPRD password="ad420e57a205c9a7d80d!"
|
||||
|
||||
create pluggable database NIHILUS admin user NIHILUS$OWNER identified by secret;
|
||||
alter pluggable database NIHILUS open;
|
||||
alter pluggable database NIHILUS save state;
|
||||
|
||||
alter session set container=NIHILUS;
|
||||
create user adm identified by "secret";
|
||||
grant sysdba to adm;
|
||||
|
||||
alias NIHILUS='rlwrap sqlplus adm/"secret"@bakura:1521/NIHILUS as sysdba'
|
||||
|
||||
create user MASTER identified by secret;
|
||||
grant connect, resource to MASTER;
|
||||
grant unlimited tablespace to MASTER;
|
||||
|
||||
|
||||
alias MASTER='rlwrap sqlplus MASTER/"secret"@bakura:1521/NIHILUS'
|
||||
|
||||
-- setup PDB
|
||||
------------
|
||||
|
||||
orapwd file=orapwANDOPRD password="oIp757a205c9?jj90yhgf"
|
||||
|
||||
create pluggable database RANDOR admin user RANDOR$OWNER identified by secret;
|
||||
alter pluggable database RANDOR open;
|
||||
alter pluggable database RANDOR save state;
|
||||
|
||||
alter session set container=RANDOR;
|
||||
create user adm identified by "secret";
|
||||
grant sysdba to adm;
|
||||
|
||||
|
||||
alias RANDOR='rlwrap sqlplus adm/"secret"@togoria:1521/RANDOR as sysdba'
|
||||
|
||||
create user REPLICA identified by secret;
|
||||
grant connect, resource to REPLICA;
|
||||
grant create materialized view to REPLICA;
|
||||
grant create view to REPLICA;
|
||||
grant create database link to REPLICA;
|
||||
grant unlimited tablespace to REPLICA;
|
||||
|
||||
alias REPLICA='rlwrap sqlplus REPLICA/"secret"@togoria:1521/RANDOR'
|
||||
|
||||
|
||||
-- master site NIHILUS
|
||||
drop table T1 purge;
|
||||
create table T1 (
|
||||
id number generated always as identity,
|
||||
n1 number(1),
|
||||
c1 varchar2(10),
|
||||
d1 DATE
|
||||
);
|
||||
|
||||
alter table T1 add constraint T1_PK primary key (ID);
|
||||
|
||||
|
||||
-- replica site RANDOR
|
||||
create database link RANDOR_TO_NIHILUS connect to MASTER identified by "secret" using 'bakura:1521/NIHILUS';
|
||||
select * from DUAL@RANDOR_TO_NIHILUS;
|
||||
|
||||
|
||||
drop materialized view MW0;
|
||||
drop materialized view MW1;
|
||||
drop materialized view MW2;
|
||||
|
||||
create materialized view MW0 as select * from T1@RANDOR_TO_NIHILUS where n1=0;
|
||||
create materialized view MW1 as select * from T1@RANDOR_TO_NIHILUS where n1=1;
|
||||
create materialized view MW2 as select * from T1@RANDOR_TO_NIHILUS where n1=2;
|
||||
|
||||
|
||||
alter session set NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS';
|
||||
select max(d1) from MW0;
|
||||
select max(d1) from MW1;
|
||||
select max(d1) from MW2;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user