我们在Amazon EC2上运行Oracle 11g数据库并尝试将其迁移到Amazon RDS。源和目标都是Oracle DB。迁移数据库后,在源和目标中验证表和数据的最佳方法是什么。如何确保在没有任何数据丢失的情况下成功迁移所有内容。
提前致谢。
答案 0 :(得分:0)
为旧数据库创建数据库链接old_db
并比较数据
select * from tab1 minus select * from tab2@old_db union all
select * from tab1@old_db minus select * from tab2@old_db
此选择的结果必须为空
按
选择所需的表名select table_name from user_tables
并构建上面的select语句,逐个表地动态执行它,比如
declare
l_found number;
l_sql varchar2(500);
begin
for l_rec in (select table_name from user_tables) loop
begin
-- assume a database link OLD_DB exists
l_sql := 'select 1 from dual where exists (select * from ' ||
l_rec.table_name || ' minus select * from ' ||
l_rec.table_name || '@OLD_DB union all ' ||
'select * from ' || l_rec.table_name ||
'@OLD_DB minus select * from ' || l_rec.table_name || ')';
dbms_output.put_line(l_sql);
execute immediate l_sql
into l_found;
dbms_output.put_line('difference found :' || l_rec.table_name);
exception
when no_data_found then
dbms_output.put_line('okay :' || l_rec.table_name);
-- okay
null;
when others then
-- error (check if table exists, ...)
dbms_output.put_line('error :' || l_rec.table_name);
end;
end loop;
end;