我想在预建表上使用物化视图,以便在迁移之前保持表同步。数据不断变化,因此需要跟踪导出开始和导入完成之间的变化。不言而喻,桌子很大,所以完全刷新太慢了。
步骤ID喜欢执行:
问题是,在创建实体化视图的那一刻,将清除旧表上的mv日志。
旧数据库: 创建表kvrtest(id号,cat号);
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.
新数据库: 创建表kvrtest(id号,cat号);
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;
此时清除mv日志
select * from MLOG$_KVRTEST; --Yields 0, a fast refresh from here does not catch these records.
有什么建议吗?
答案 0 :(得分:4)
当您使用REFRESH标记创建新的MATERIALIZED VIEW时,日志表正在清除,因为我们的视图实际上是在创建之后。
CREATE MATERIALIZED VIEW kvrtest
ON PREBUILT TABLE WITHOUT REDUCED PRECISION
USING INDEX
REFRESH FORCE ON DEMAND
AS
如果不想清除您的日志表,请使用NEVER REFRESH然后更改为REFRESH ON DEMAND,如下所示:
CREATE MATERIALIZED VIEW kvrtest
ON PREBUILT TABLE WITHOUT REDUCED PRECISION
USING INDEX
NEVER REFRESH
AS
select * from kvrtest@oldDb;
让我们看一下我们的日志表
select * from MLOG$_KVRTEST;
我们有两排,真好!然后
ALTER MATERIALIZED VIEW kvrtest
REFRESH ON DEMAND;
然后刷新视图日志表将再次清除。