Question

I'd like to use materialized view on prebuilt table to keep a table in sync before a migration. The data is changing constantly, so the changes between export start and import finish need to be tracked. It goes without saying the table is huge so a complete refresh is too slow.

Steps id like to perform:

  1. Create table on new db.
  2. Create mv log on old db table.
  3. Import data from old db to new db.
  4. Create materialized view on the new db on the prebuild table and keep refresh it from the point when the mv log was created.

The problem is that the moment the materialized view is created the mv log on the old table is purged.

Old DB: create table kvrtest (id number, cat number);

alter table kvrtest add ( constraint pkkvrtest primary key (id) using index);

insert into kvrtest (id, cat) values (1, 1);
commit;

CREATE MATERIALIZED VIEW LOG ON kvrtest WITH PRIMARY KEY;

insert into kvrtest (id, cat) values (2, 1);
insert into kvrtest (id, cat) values (3, 2);
commit;

select * from MLOG$_KVRTEST; --Yields 2, these should be caught by a fast refresh.

New DB: create table kvrtest (id number, cat number);

alter table kvrtest add ( constraint pkkvrtest primary key (id) using index);

insert into kvrtest (id, cat) values (1, 1); --Simulate import.

commit;

CREATE MATERIALIZED VIEW kvrtest 
ON PREBUILT TABLE WITHOUT REDUCED PRECISION
USING INDEX
REFRESH FORCE ON DEMAND
AS 
select * from kvrtest@oldDb;

At this point the mv log is purged

select * from MLOG$_KVRTEST; --Yields 0, a fast refresh from here does not catch these records.

Any suggestions?

Was it helpful?

Solution

when you create new MATERIALIZED VIEW with REFRESH tag log table is clearing, because our view is actually after creating.

CREATE MATERIALIZED VIEW kvrtest 
ON PREBUILT TABLE WITHOUT REDUCED PRECISION
USING INDEX
REFRESH FORCE ON DEMAND
AS 

if don't want to clear your log table use NEVER REFRESH and then change to REFRESH ON DEMAND like this:

CREATE MATERIALIZED VIEW kvrtest 
ON PREBUILT TABLE WITHOUT REDUCED PRECISION
USING INDEX
NEVER REFRESH
AS 
select * from kvrtest@oldDb;

let's see our log table

select * from MLOG$_KVRTEST;

we have two rows, nice! and then

ALTER MATERIALIZED VIEW kvrtest 
    REFRESH ON DEMAND;

then after refresh view log table will clear again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top