点击上方蓝色字关注我们~
先从Online Move Datafile说起,Online Move Datafile是12.1的新特性,在12c之前如果想要move datafile通常需要下列步骤:
1.offline datafile
2.backup as copy数据文件到指定路径
3.switch datafile to copy切换控制文件中数据文件路径
4.由于offline datafile不会做检查点,所以在online之前需要recover datafile
5.online datafile
Oracle 12.1推出了Online Move Datafile的新特性,那么Oracle是如何通过一条命令就搞定了12c之前较为繁琐的步骤呢?下面将通过测试验证进行深入分析。
测试环境12.2,测试验证过程使用了gdb、10046、strace,gdb在kcffo_mv_prepare、kcffo_mv_copy_loop、kcffo_mv_remove_secondary等重要函数打上断点。10046跟踪Online Move Datafile的会话,strace跟踪dbwr进程。
发起数据文件12的online move操作:
SQL> alter database move datafile 12 to '/oracle/app/oracle/oradata/ORA12C/B727E6DDCF847CEDE0555D384BFF4A69/datafile/12_mv.dbf';
通过分析发现其内部操作如下:
第一步:调用kcffo_movefile函数开始对数据文件进行online move,这个move期间session都会持有对应数据文件的MV锁。
Moving datafile /tmp/12_mvnew.dbf (12) to /oracle/app/oracle/oradata/ORA12C/B727E6DDCF847CEDE0555D384BFF4A69/datafile/12_mvnew.dbf
ADDR KADDR SID TY ID1 ID2 LMODE REQUEST CTIME BLOCK CON_ID
---------------- ---------------- ---------- -- ---------- ---------- ---------- ---------- ---------- ---------- ----------
0000000066186B00 0000000066186B80 237 IS 0 0 4 0 1282 0 0
0000000066187968 00000000661879E8 237 TO 71021 1 3 0 31075 0 1
0000000066187B98 0000000066187C18 237 MR 12 0 4 0 1282 0 0
0000000066189EF8 0000000066189F78 237 MV 1 12 4 0 1282 0 0
0000000066186588 0000000066186608 237 MV 0 12 6 0 1282 0 0
第二步:调用kcffo_mv_prepare函数对数据文件进行初始化。
WAIT #140452576418240: nam='db file single write' ela= 34 file#=12 block#=1 blocks=1 obj#=0 tim=95452872153
WAIT #140452576418240: nam='Disk file operations I/O' ela= 11369 FileOperation=5 fileno=0 filetype=2 obj#=0 tim=95452883593
WAIT #140452576418240: nam='control file sequential read' ela= 12 file#=0 block#=1 blocks=1 obj#=0 tim=95452883736
WAIT #140452576418240: nam='control file sequential read' ela= 6 file#=1 block#=1 blocks=1 obj#=0 tim=95452883770
WAIT #140452576418240: nam='control file sequential read' ela= 6 file#=0 block#=15 blocks=1 obj#=0 tim=95452883788
WAIT #140452576418240: nam='control file sequential read' ela= 6 file#=0 block#=17 blocks=1 obj#=0 tim=95452883804
WAIT #140452576418240: nam='control file sequential read' ela= 6 file#=0 block#=89 blocks=1 obj#=0 tim=95452883826
WAIT #140452576418240: nam='control file sequential read' ela= 6 file#=0 block#=23 blocks=1 obj#=0 tim=95452883844
WAIT #140452576418240: nam='control file parallel write' ela= 1334 files=2 block#=90 requests=2 obj#=0 tim=95452885195
WAIT #140452576418240: nam='control file parallel write' ela= 1096 files=2 block#=24 requests=2 obj#=0 tim=95452886333
WAIT #140452576418240: nam='control file parallel write' ela= 862 files=2 block#=18 requests=2 obj#=0 tim=95452887230
WAIT #140452576418240: nam='control file parallel write' ela= 837 files=2 block#=16 requests=2 obj#=0 tim=95452888102
WAIT #140452576418240: nam='control file parallel write' ela= 833 fi