创建测试表并模拟truncate的场景:
SQL> create table trutab as select * from t1; Table created. SQL> select count(*) from trutab; COUNT(*) ---------- 10000 SQL> commit 2 ; Commit complete. SQL> SQL> SQL> truncate table trutab; Table truncated. SQL> select count(*) from trutab; COUNT(*) ---------- 0 SQL> select segment_name,tablespace_name from dba_segments where segment_name='TRUTAB' and owner='LUDA'; SEGMENT_NAME TABLESPACE_NAME ---------------------------------------- ---------------------------------------- TRUTAB USERS
加载mdata
MDATA>reload dict Start reload dict,Mon Jan 12 13:46:45 CST 2015 load BOOTSTRAP$ success. load TAB$ success. load COL$ success. load OBJ$ success. load USER$ success. load PROPS$ success. load TABPART$ success. load TABSUBPART$ success. load IND$ success. End reload dict,Mon Jan 12 13:46:51 CST 2015,reload success. MDATA>list table luda OWNER TABLE --------------- -------------- LUDA T2 LUDA T1 LUDA TRUTAB owner:LUDA has 3 rows selected.
通过scan的方式扫描被truncate的表所在的tablespace
MDATA>unload table luda.trutab unload schema:LUDA;tab:TRUTAB tabName:LUDA.TRUTAB,dic_obj:com.olm.b.H@f0ca71,getFileid:4,getBlockid:195 0 rows unloaded MDATA>scan extent tablespace 4 datafile 4 scan extent start: Mon Jan 12 13:48:14 CST 2015 scanning extent... scanning extent finished. scan extent completed: Mon Jan 12 13:48:15 CST 2015 MDATA>unload table luda.trutab unload schema:LUDA;tab:TRUTAB tabName:LUDA.TRUTAB,dic_obj:com.olm.b.H@26e5d8,getFileid:4,getBlockid:195 0 rows unloaded MDATA>scan extent tablespace 4 datafile 4 auto scan extent [tablespace <ts #> [datafile <rfile #>] ] [object <data_object_data>] parallel [parallel_degree]
scan做操完成后,对该表执行unload操作
MDATA>unload table luda.trutab object auto Auto mode truncated table. unload schema:LUDA;tab:TRUTAB tabName:LUDA.TRUTAB,dic_obj:com.olm.b.H@cd1365,getFileid:4,getBlockid:195 10000 rows unloaded MDATA>
导出恢复的数据后,通过sqlload工具将导出的数据恢复到trutab表中:
[oracle@DB01 data]$ sqlldr luda/luda control=LUDA.TRUTAB.ctl SQL*Loader: Release 10.2.0.4.0 - Production on Mon Jan 12 13:52:44 2015 Copyright (c) 1982, 2007, Oracle. All rights reserved. Commit point reached - logical record count 2501 Commit point reached - logical record count 5002 Commit point reached - logical record count 7503 Commit point reached - logical record count 10000
恢复完成后验证恢复:
[oracle@DB01 data]$ sqlplus '/as sysdba' SQL*Plus: Release 10.2.0.4.0 - Production on Mon Jan 12 13:52:54 2015 Copyright (c) 1982, 2007, Oracle. All Rights Reserved. Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> select count(*) from luda.trutab; COUNT(*) ---------- 10000
至此truncate的恢复已经完成。提示一个小技巧,mdata的scan功能支持并行模式