9

oracle跨平台,跨版本,大数据量迁移之xtts的传输表空间 -m6米乐安卓版下载

原创 狗剩儿 2022-03-22
2444

文章目录

一、背景介绍

1.1源端开启归档模式
1.2备份文件的传输方案


二、实际操作步骤
2.1导出创建源库用户脚本
2.2 源端进行0级rman备份
2.3 目标端提取0级rman备份
2.4 源端进行1级rman备份
2.5 目标端提取1级rman备份
2.6 源端提取用户对象信息
2.7 源端表空间设置只读(停机开始)
2.8源端进行最后一次1级rman备份
2.9 源端导出表空间元数据
2.10 源端还原表空间可读写(停机结束)
2.11 目标端应用1级rman增量备份
2.12 目标端导入用户权限和对象
2.13 目标端导入表空间元数据
2.14 目标端修改用户默认表空间
2.15 目标端修改表空间可读写(迁移完成)


三、完善调整以及迁移验证
3.1重建序列
3.2 编译失效对象
3.3 收集统计信息
3.4 源端与目标端的数据对比


总结


想必很多小伙伴工作中都遇到过迁移数据库的任务,但是我们做的最多的方式就是通过数据泵导出导入来实现,此方面很简单也很靠谱,但如果没有足够的停机时间窗口的时候,显然这个数据泵的方式就不能满足我们的工作要求,下面给大家详细介绍下一个真实案例,如何通过传输表空间xtts的技术来实现小停机窗口实现数据库迁移。(跨平台、跨版本)


提示:以下是本篇文章正文内容,下面案例可供参考

源端: windows2008r2 oracle11.2.0.1
目标端: linux7.9 oracle19.9.0 rac asm
当然其他的源端平台也有些需要注意的事项:例如aix的oracle数据到linux下需要一个转换步骤。

1.1源端开启归档模式

sqlplus / as sysdba
alter system set log_archive_dest_1='location=d:\archivelog' scope=spfile sid='*';
shutdown immedate
startup mount
alter database archivelog;
archive log list;
alter database open;
shutdown immediate
startup

创建d:\rman目录
自动删除归档脚本参考:
delarch.bat


rmancmdfile=d:\rman\rmandelete.txt

rmandelete.txt内容:

connect target /
run{
delete nopromptarchivelog all completed before 'sysdate-0';
crosscheck archivelog all;
delete noprompt expired archivelog all;
}

1.2备份文件的传输方案

因需要备份文件的传输,实施时应考虑如何高效的将备份文件从源端传输到目标端。
例如:nfs、acfs或者网络拷贝等

此计划表是某次实施过程的实际计划表,在实际操作之前要完成第一部分所有准备工作。如下:(只供参考,对本文无指导意义)

2.1导出创建源库用户脚本

后续会在目标端完成用户创建使用

set line 160
set pagesize 0
spool create_user.sql
select 'create user '||a.name||' identified by values '||''''||a.password||''''||';' from user$ a left join dba_users b on a.name=b.username where b.default_tablespace in('htbase');
spool off

2.2 源端进行0级rman备份

启用块跟踪,加快增量备份速度
sql> alter database enable block change tracking using file 'd:\rman\change.rman';
sql> select status, filename from v$block_change_tracking;
status     filename
---------- -------------------------------------------------
enabled    e:\rman\change.rman
sql> exit
rman target /
rman>
run {
allocate channel t1 type disk;
allocate channel t2 type disk;
allocate channel t3 type disk;
allocate channel t4 type disk;
backup as compressed backupset incrementallevel=0 tablespace htbase format 'd:\rman\emrlszy0_%u' tag=emrlszy0;
release channel t1;
release channel t2;
release channel t3;
release channel t4;
}
实际操作时备份操作拆分成10个备份集:
rman> list backup tag=emrlszy0;
备份集列表
===================
bs 关键字  类型 lv 大小       设备类型 经过时间 完成时间
------- ---- -- ---------- ----------- ------------ ----------
12      incr 0  67.30g     disk        00:48:08     02-2月 -21
        bp 关键字: 12   状态: available  已压缩: no  标记: ls
段名:d:\rman\ls_0lvm74vu_1_1
  备份集 12 中的数据文件列表
  文件 lv 类型 ckp scn    ckp 时间   名称
  ---- -- ---- ---------- ---------- ----
  14   0  incr 69888378   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase10.dbf
  24   0  incr 69888378   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase20.dbf
  34   0  incr 69888378   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase30.dbf
bs 关键字  类型 lv 大小       设备类型 经过时间 完成时间
------- ---- -- ---------- ----------- ------------ ----------
13      incr 0  70.80g     disk        00:49:28     02-2月 -21
        bp 关键字: 13   状态: available  已压缩: no  标记: ls
段名:d:\rman\ls_0kvm74vu_1_1
  备份集 13 中的数据文件列表
  文件 lv 类型 ckp scn    ckp 时间   名称
  ---- -- ---- ---------- ---------- ----
  13   0  incr 69888375   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase09.dbf
  23   0  incr 69888375   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase19.dbf
  33   0  incr 69888375   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase29.dbf
bs 关键字  类型 lv 大小       设备类型 经过时间 完成时间
------- ---- -- ---------- ----------- ------------ ----------
14      incr 0  80.43g     disk        00:58:24     02-2月 -21
        bp 关键字: 14   状态: available  已压缩: no  标记: ls
段名:d:\rman\ls_0jvm74vu_1_1
  备份集 14 中的数据文件列表
  文件 lv 类型 ckp scn    ckp 时间   名称
  ---- -- ---- ---------- ---------- ----
  12   0  incr 69888372   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase08.dbf
  22   0  incr 69888372   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase18.dbf
  32   0  incr 69888372   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase28.dbf
bs 关键字  类型 lv 大小       设备类型 经过时间 完成时间
------- ---- -- ---------- ----------- ------------ ----------
15      incr 0  91.03g     disk        01:04:59     02-2月 -21
        bp 关键字: 15   状态: available  已压缩: no  标记: ls
段名:d:\rman\ls_0ivm74vt_1_1
  备份集 15 中的数据文件列表
  文件 lv 类型 ckp scn    ckp 时间   名称
  ---- -- ---- ---------- ---------- ----
  11   0  incr 69888369   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase07.dbf
  21   0  incr 69888369   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase17.dbf
  31   0  incr 69888369   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase27.dbf
bs 关键字  类型 lv 大小       设备类型 经过时间 完成时间
------- ---- -- ---------- ----------- ------------ ----------
16      incr 0  92.88g     disk        01:06:06     02-2月 -21
        bp 关键字: 16   状态: available  已压缩: no  标记: ls
段名:d:\rman\ls_0fvm74vt_1_1
  备份集 16 中的数据文件列表
  文件 lv 类型 ckp scn    ckp 时间   名称
  ---- -- ---- ---------- ---------- ----
  8    0  incr 69888360   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase04.dbf
  18   0  incr 69888360   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase14.dbf
  28   0  incr 69888360   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase24.dbf
bs 关键字  类型 lv 大小       设备类型 经过时间 完成时间
------- ---- -- ---------- ----------- ------------ ----------
17      incr 0  92.01g     disk        01:06:35     02-2月 -21
        bp 关键字: 17   状态: available  已压缩: no  标记: ls
段名:d:\rman\ls_0hvm74vt_1_1
  备份集 17 中的数据文件列表
  文件 lv 类型 ckp scn    ckp 时间   名称
  ---- -- ---- ---------- ---------- ----
  10   0  incr 69888366   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase06.dbf
  20   0  incr 69888366   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase16.dbf
  30   0  incr 69888366   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase26.dbf
bs 关键字  类型 lv 大小       设备类型 经过时间 完成时间
------- ---- -- ---------- ----------- ------------ ----------
18      incr 0  92.62g     disk        01:06:47     02-2月 -21
        bp 关键字: 18   状态: available  已压缩: no  标记: ls
段名:d:\rman\ls_0gvm74vt_1_1
  备份集 18 中的数据文件列表
  文件 lv 类型 ckp scn    ckp 时间   名称
  ---- -- ---- ---------- ---------- ----
  9    0  incr 69888363   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase05.dbf
  19   0  incr 69888363   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase15.dbf
  29   0  incr 69888363   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase25.dbf
bs 关键字  类型 lv 大小       设备类型 经过时间 完成时间
------- ---- -- ---------- ----------- ------------ ----------
19      incr 0  93.51g     disk        01:07:02     02-2月 -21
        bp 关键字: 19   状态: available  已压缩: no  标记: ls
段名:d:\rman\ls_0evm74vt_1_1
  备份集 19 中的数据文件列表
  文件 lv 类型 ckp scn    ckp 时间   名称
  ---- -- ---- ---------- ---------- ----
  7    0  incr 69888358   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase03.dbf
  17   0  incr 69888358   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase13.dbf
  27   0  incr 69888358   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase23.dbf
bs 关键字  类型 lv 大小       设备类型 经过时间 完成时间
------- ---- -- ---------- ----------- ------------ ----------
20      incr 0  95.99g     disk        01:07:21     02-2月 -21
        bp 关键字: 20   状态: available  已压缩: no  标记: ls
段名:d:\rman\ls_0dvm74vt_1_1
  备份集 20 中的数据文件列表
  文件 lv 类型 ckp scn    ckp 时间   名称
  ---- -- ---- ---------- ---------- ----
  6    0  incr 69888356   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase02.dbf
  16   0  incr 69888356   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase12.dbf
  26   0  incr 69888356   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase22.dbf
bs 关键字  类型 lv 大小       设备类型 经过时间 完成时间
------- ---- -- ---------- ----------- ------------ ----------
21      incr 0  96.00g     disk        01:07:26     02-2月 -21
        bp 关键字: 21   状态: available  已压缩: no  标记: ls
段名:d:\rman\ls_0cvm74vt_1_1
  备份集 21 中的数据文件列表
  文件 lv 类型 ckp scn    ckp 时间   名称
  ---- -- ---- ---------- ---------- ----
  5    0  incr 69888354   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase01.dbf
  15   0  incr 69888354   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase11.dbf
  25   0  incr 69888354   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase21.dbf

2.3 目标端提取0级rman备份

将源端的rman备份文件传输到目标端后,按照备份集进行备份提取操作,注意标号对应表空间:
本小节不全部列举,不同备份集都需要进行对应提取,本案例2.1中有10个备份集:

conn / as sysdba
set serveroutput on;
declare
devtype varchar2(256);
done boolean;
begin
devtype:=sys.dbms_backup_restore.deviceallocate (type=>'',ident=>'t1');
sys.dbms_backup_restore.restoresetdatafile;
sys.dbms_backup_restore.restoredatafileto(dfnumber=>14,toname=>' datac1/emrlszy/htbase10.dbf');
sys.dbms_backup_restore.restoredatafileto(dfnumber=>24,toname=>' datac1/emrlszy/htbase20.dbf');
sys.dbms_backup_restore.restoredatafileto(dfnumber=>34,toname=>' datac1/emrlszy/htbase30.dbf');
sys.dbms_backup_restore.restorebackuppiece(done=>done,handle=>'/xtts/ls_0lvm74vu_1_1', params=>null);
sys.dbms_backup_restore.devicedeallocate;
end;
/

注意:
1、如果提取失败建议使用伪实例进行提取操作
2、不同备份集的提取注意要切换不同的会话提取
3、如表空间太多可以通过rman备份设置在一个备份集中,可添加 filesperset 300 参数

2.4 源端进行1级rman备份

c:\users\administrator>set  oracle_sid=emrlszy
c:\users\administrator>rman target /
恢复管理器: release 11.2.0.1.0 - production on 星期日 1月 19 11:14:30 2020
米乐app官网下载 copyright (c) 1982, 2007, oracle.  all rights reserved.
连接到目标数据库: emrlszy (dbid=278480429)
rman>run {
allocate channel t1 type disk;
backup incremental level=1 tablespace htbaseformat 'd:\rman\emrlszy1_%u' tag=emrlszy1;
release channel t1;
}
rman>list backup;
bs 关键字  类型 lv 大小       设备类型 经过时间 完成时间
------- ---- -- ---------- ----------- ------------ ----------
22      incr 1  264.00k    disk        00:00:04     02-2月 -21
        bp 关键字: 22   状态: available  已压缩: no  标记: emrlszy1
段名:\\192.168.16.51\xtts\emrlszy1_0mvm7blr_1_1
  备份集 22 中的数据文件列表
  文件 lv 类型 ckp scn    ckp 时间   名称
  ---- -- ---- ---------- ---------- ----
  5    1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase01.dbf
  6    1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase02.dbf
  7    1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase03.dbf
  8    1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase04.dbf
  9    1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase05.dbf
  10   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase06.dbf
  11   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase07.dbf
  12   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase08.dbf
  13   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase09.dbf
  14   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase10.dbf
  15   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase11.dbf
  16   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase12.dbf
  17   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase13.dbf
  18   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase14.dbf
  19   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase15.dbf
  20   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase16.dbf
  21   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase17.dbf
  22   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase18.dbf
  23   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase19.dbf
  24   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase20.dbf
  25   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase21.dbf
  26   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase22.dbf
  27   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase23.dbf
  28   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase24.dbf
  29   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase25.dbf
  30   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase26.dbf
  31   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase27.dbf
  32   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase28.dbf
  33   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase29.dbf
  34   1  incr 69900005   02-2月 -21 d:\app\administrator\oradata\emrlszy\htbase30.dbf
rman>

2.5 目标端提取1级rman备份

sqlplus sys/xxxxx@emrlszy as sysdba
sql>
sql> set serveroutput on;
declare
    outhandle varchar2(512) ;
outtag varchar2(30) ;
    done boolean ;
    failover boolean ;
devtype varchar2(512);
    begin
dbms_output.put_line('entering rollforward');
    -- now the rolling forward.
devtype := sys.dbms_backup_restore.deviceallocate;
sys.dbms_backup_restore.applysetdatafile(check_logical => false, cleanup => false) ; 
dbms_output.put_line('after applysetdatafile');
sys.dbms_backup_restore.applydatafileto(dfnumber=>8,toname=>' datac1/emrlszy/htbase04.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>12,toname=>' datac1/emrlszy/htbase08.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>16,toname=>' datac1/emrlszy/htbase12.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>20,toname=>' datac1/emrlszy/htbase16.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>24,toname=>' datac1/emrlszy/htbase20.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>28,toname=>' datac1/emrlszy/htbase24.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>32,toname=>' datac1/emrlszy/htbase28.dbf'',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>7,toname=>' datac1/emrlszy/htbase03.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>11,toname=>' datac1/emrlszy/htbase07.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>15,toname=>' datac1/emrlszy/htbase11.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>19,toname=>' datac1/emrlszy/htbase15.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>23,toname=>' datac1/emrlszy/htbase19.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>27,toname=>' datac1/emrlszy/htbase23.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>31,toname=>' datac1/emrlszy/htbase27.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>6,toname=>' datac1/emrlszy/htbase02.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>10,toname=>' datac1/emrlszy/htbase06.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>14,toname=>' datac1/emrlszy/htbase10.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>18,toname=>' datac1/emrlszy/htbase14.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>22,toname=>' datac1/emrlszy/htbase18.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>26,toname=>' datac1/emrlszy/htbase22.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>30,toname=>' datac1/emrlszy/htbase26.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>34,toname=>' datac1/emrlszy/htbase30.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>5,toname=>' datac1/emrlszy/htbase01.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>9,toname=>' datac1/emrlszy/htbase05.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>13,toname=>' datac1/emrlszy/htbase09.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>17,toname=>' datac1/emrlszy/htbase13.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>21,toname=>' datac1/emrlszy/htbase17.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>25,toname=>' datac1/emrlszy/htbase21.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>29,toname=>' datac1/emrlszy/htbase25.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>33,toname=>' datac1/emrlszy/htbase29.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
dbms_output.put_line('done: applydatafileto');
  -- restore set piece
sys.dbms_backup_restore.restoresetpiece(handle     => '/xtts/emrlszy1_05vh67t3_1_1',tag => null, fromdisk => true, recid => 0, stamp => 0) ;
dbms_output.put_line('done: restoresetpiece');
   -- restore backup piece
sys.dbms_backup_restore.restorebackuppiece(done =>  done, params =>  null, outhandle  =>outhandle,outtag =>outtag, failover => failover);
dbms_output.put_line('done: restorebackuppiece');
sys.dbms_backup_restore.restorecancel(true);
sys.dbms_backup_restore.devicedeallocate;
   end;
   /

根据实际情况可多次进行2.4~2.5的1级增量备份操作,但最多操作8次,否则块跟踪记录会被覆盖,再次执行导致进行全库扫描,导致长时间等待就失去了此方案意义

所以从开启块跟踪到迁移完成要控制在8次备份之内。

2.6 源端提取用户对象信息

此时操作后,最好源端不会再新增对象,否则新增对象需要手动恢复。

expdp '/ as sysdba' directory=xtts_dmp dumpfile=meta_%u.dmp logfile=meta.log schemas=用户名1,用户名2,用户名3 content=metadata_only parallel=8 cluster=n exclude=table,index,sequence,statistics

2.7 源端表空间设置只读(停机开始)

sql> conn /as sysdba
已连接。
sql>
alter tablespace htbase read only;

2.8源端进行最后一次1级rman备份

rman>run {
allocate channel t1 type disk;
backup incremental level=1 tablespace htbaseformat 'd:\rman\emrlszy1_%u' tag=emrlszy1;
release channel t1;
}

2.9 源端导出表空间元数据

测试期间,考虑到最小停机影响,先备份到本地:d:\dmpts

create directory dmp as 'd:\dmpts;

正式割接直接备份到目标端:

create directory xtts_dmp as '\\192.168.xx.xx\xtts\';
grant read,write on directory xtts_dmp to public;
expdp '/ as sysdba' directory=xtts_dmp dumpfile=tts.dmp transport_tablespaces=htbase exclude=statistics

2.10 源端还原表空间可读写(停机结束)

sqlplus / as sysdba
alter tablespace htbase read write;
select tablespace_name,status from dba_tablespaces; 

2.11 目标端应用1级rman增量备份

sql>set serveroutput on;
declare
    outhandle varchar2(512) ;
outtag varchar2(30) ;
    done boolean ;
    failover boolean ;
devtype varchar2(512);
    begin
dbms_output.put_line('entering rollforward');
    -- now the rolling forward.
devtype := sys.dbms_backup_restore.deviceallocate;
sys.dbms_backup_restore.applysetdatafile(check_logical => false, cleanup => false); 
dbms_output.put_line('after applysetdatafile');
sys.dbms_backup_restore.applydatafileto(dfnumber=>8,toname=>' datac1/emrlszy/htbase04.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>12,toname=>' datac1/emrlszy/htbase08.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>16,toname=>' datac1/emrlszy/htbase12.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>20,toname=>' datac1/emrlszy/htbase16.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>24,toname=>' datac1/emrlszy/htbase20.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>28,toname=>' datac1/emrlszy/htbase24.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>32,toname=>' datac1/emrlszy/htbase28.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>7,toname=>' datac1/emrlszy/htbase03.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>11,toname=>' datac1/emrlszy/htbase07.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>15,toname=>' datac1/emrlszy/htbase11.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>19,toname=>' datac1/emrlszy/htbase15.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>23,toname=>' datac1/emrlszy/htbase19.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>27,toname=>' datac1/emrlszy/htbase23.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>31,toname=>' datac1/emrlszy/htbase27.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>6,toname=>' datac1/emrlszy/htbase02.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>10,toname=>' datac1/emrlszy/htbase06.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>14,toname=>' datac1/emrlszy/htbase10.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>18,toname=>' datac1/emrlszy/htbase14.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>22,toname=>' datac1/emrlszy/htbase18.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>26,toname=>' datac1/emrlszy/htbase22.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>30,toname=>' datac1/emrlszy/htbase26.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>34,toname=>' datac1/emrlszy/htbase30.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>5,toname=>' datac1/emrlszy/htbase01.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>9,toname=>' datac1/emrlszy/htbase05.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>13,toname=>' datac1/emrlszy/htbase09.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>17,toname=>' datac1/emrlszy/htbase13.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>21,toname=>' datac1/emrlszy/htbase17.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>25,toname=>' datac1/emrlszy/htbase21.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>29,toname=>' datac1/emrlszy/htbase25.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
sys.dbms_backup_restore.applydatafileto(dfnumber=>33,toname=>' datac1/emrlszy/htbase29.dbf',fuzziness_hint => 0, max_corrupt => 0, islevel0 => 0,recid => 0, stamp => 0);
dbms_output.put_line('done: applydatafileto');
sys.dbms_backup_restore.restoresetpiece(handle => '/xtts/emrlszy1_0mvm7blr_1_1',tag => null, fromdisk => true, recid => 0, stamp => 0) ;
dbms_output.put_line('done: restoresetpiece');
sys.dbms_backup_restore.restorebackuppiece(done =>  done, params =>  null, outhandle  =>outhandle,outtag =>outtag, failover => failover);
dbms_output.put_line('done: restorebackuppiece');
sys.dbms_backup_restore.restorecancel(true);
sys.dbms_backup_restore.devicedeallocate;
   end;
   /

2.12 目标端导入用户权限和对象

如是容器数据库必须进入到容器pdb内内操作
sql>alter session set container=emrlszy;   
或sqlplu ssys/xxxxxx@emrlszy as sysdba
show pdbs;
目标端导入
impdp 'sys/"xxxxxxx"@emrlszy as sysdba' directory=xtts_dmp dumpfile=meta_%u.dmp logfile=meta-imp.log schemas=用户名1,用户名2,用户名3

本步骤建议在 2.15 小节之后操作

2.13 目标端导入表空间元数据

create directory xtts_dmp as '/xtts';
grant read,write on directory xtts_dmp to public;
$ cat impdp-par.txt 
transport_datafiles=' datac1\emrlszy\htbase01.dbf',' datac1\emrlszy\htbase02dbf',' datac1\emrlszy\htbase03.dbf',' datac1\emrlszy\htbase04.dbf',' datac1\emrlszy\htbase05.dbf',' datac1\emrlszy\htbase06.dbf',' datac1\emrlszy\htbase07.dbf',' datac1\emrlszy\htbase08.dbf',' datac1\emrlszy\htbase09.dbf',' datac1\emrlszy\htbase10.dbf',' datac1\emrlszy\htbase11.dbf',' datac1\emrlszy\htbase12.dbf',' datac1\emrlszy\htbase13.dbf',' datac1\emrlszy\htbase14.dbf',' datac1\emrlszy\htbase15.dbf',' datac1\emrlszy\htbase16.dbf',' datac1\emrlszy\htbase17.dbf',' datac1\emrlszy\htbase18.dbf',' datac1\emrlszy\htbase19.dbf',' datac1\emrlszy\htbase20.dbf',' datac1\emrlszy\htbase21.dbf',' datac1\emrlszy\htbase22.dbf',' datac1\emrlszy\htbase23.dbf',' datac1\emrlszy\htbase24.dbf',' datac1\emrlszy\htbase25.dbf',' datac1\emrlszy\htbase26.dbf',' datac1\emrlszy\htbase27.dbf',' datac1\emrlszy\htbase28.dbf',' datac1\emrlszy\htbase29.dbf', ' datac1\emrlszy\htbase30.dbf'
 
impdp 'sys/"xxxxxxx"@emrlszy as sysdba' dumpfile=tts.dmp directory=xtts_dmp parfile=impdp-par.txt
$ cd /dmp/xtts
$ sqlplussys/xxxxxx@emrlszy as sysdba
sql> show pdbs;      
测试普通用户连接:
sql> conn xxx/xxx@emrlszy
sql> select name from v$tablespace;
sql> select name from v$datafile;
sql> select count(*) from user_tables;

2.14 目标端修改用户默认表空间

$ sqlplussys/xxxxxxx@htemr as sysdba
show pdbs;
alter user 用户名1	default tablespace htbase; 
alter user 用户名2	default tablespace htbase;
alter user 用户名3	default tablespace htbase;
......

2.15 目标端修改表空间可读写(迁移完成)

$ sqlplussys/xxxxxxx@emrlszy as sysdba
show pdbs;
alter tablespace htbase read write;
select tablespace_name,status from dba_tablespaces;

至此,我们数据库迁移已然完成,之后需要配合应用验证数据库的完整性

3.1重建序列

视实际情况而定

单机到rac优化性能考虑:
目标端删除序列:
select 'drop sequence "'||sequence_owner||'"."'||sequence_name ||'";' seqddl from dba_sequences where sequence_owner not in
 (select name from system.logstdby$skip_support
 where action=0);
在源端提取创建序列:
set heading off feedback off trimspool on escape off
set long 1000 linesize 1000 pagesize 0
col seqddl format a300
spool tts_create_seq.sql
select regexp_replace(dbms_metadata.get_ddl('sequence',sequence_name,sequence_owner), '^.*(create sequence.*cycle).*$', 'drop sequence "'||sequence_owner||'"."'||sequence_name ||'";'||chr(10)||'\1;')||';' seqddl
 from dba_sequences where sequence_owner not in
 (select name from system.logstdby$skip_support where action=0);
spool off;
脚本需根据情况调整 cache大小和 order顺序。
注意:原cache为20的都改为1000
no order的可能需改成order,需要问业务是否能跳号?还是说序列得保持顺序号。不清楚就先不变。等业务测试反馈。

3.2 编译失效对象

$ sqlplussys/xxxxxxx@emrlszy as sysdba
show pdbs;
@$oracle_home/rdbms/admin/utlrp.sql
select count(*) from dba_objects where status='invalid';
count(*)
----------
0

3.3 收集统计信息

详细略

3.4 源端与目标端的数据对比

对象数量比对:
select owner,object_type, count(*)
  from dba_objects
 where owner in ('用户名1','用户名2','用户名3'...)
 group by owner,object_type
 order by count(*) desc;

那么,到此我们就完整的完成了数据库的迁移,接下来就由应用接手测试业务就ok了,经过实际测试,利用此方法,停机窗口可控制在1~2小时内。针对库大小的不同,我们前期准备时间相对就会不同。多理解,多操作,拒绝ctrl c、ctrl v!!!

最后修改时间:2022-03-23 09:20:15
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【米乐app官网下载的版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

网站地图