【问题标题】:How to validate the database after migration迁移后如何验证数据库
【发布时间】:2016-10-01 15:36:23
【问题描述】:

我们在 Amazon EC2 上运行 Oracle 11g 数据库并尝试将其迁移到 Amazon RDS。源和目标都是 Oracle DB。迁移数据库后,验证源和目标中的表和数据的最佳方法是什么。如何确保所有内容都成功迁移而不会丢失任何数据。

提前致谢。

【问题讨论】:

    标签: oracle amazon-web-services amazon-ec2 database-migration


    【解决方案1】:

    创建一个数据库链接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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-12
      • 1970-01-01
      • 2012-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多