<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AnySQL.net &#187; Truncate</title>
	<atom:link href="http://www.anysql.net/tag/truncate/feed" rel="self" type="application/rss+xml" />
	<link>http://www.anysql.net</link>
	<description>SQLULDR2, DataCopy, DataSync, WebChart, OraMon, AUL/MyDUL, 性能优化及容量分析</description>
	<lastBuildDate>Wed, 14 Jul 2010 09:27:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>在AUL中如何轻松恢复TRUNCATE的表?</title>
		<link>http://www.anysql.net/aulmydul/aul_truncate_recovery.html</link>
		<comments>http://www.anysql.net/aulmydul/aul_truncate_recovery.html#comments</comments>
		<pubDate>Tue, 19 Dec 2006 04:50:59 +0000</pubDate>
		<dc:creator>anysql</dc:creator>
				<category><![CDATA[AUL/MyDUL]]></category>
		<category><![CDATA[Truncate]]></category>
		<category><![CDATA[数据恢复]]></category>

		<guid isPermaLink="false">http://www.anysql.net/wordpress/uncategorized/%e5%9c%a8aul%e4%b8%ad%e5%a6%82%e4%bd%95%e8%bd%bb%e6%9d%be%e6%81%a2%e5%a4%8dtruncate%e7%9a%84%e8%a1%a8.html</guid>
		<description><![CDATA[&#160; &#160; 不小心Truncate表的事情也是有的, 其中大部份时因为工具连错了库, 从儿跑错了角本. 遇到这种事情而没有备份时怎么办呢? 首先要停止数据库, 将这个表所在的表空间的文件拷贝出来, 因为Oracle在Truncate只时将相应Segment的第一个块格式化掉了, 而后面的都还存在, 到下次用时到才真正地重新格式化. 下面来讲一个Truncate表后进行恢复的例子: SQL&#62; CREATE TABLE T_TRUNCATE AS SELECT * FROM TAB; Table created. SQL&#62; SELECT COUNT(*) FROM T_TRUNCATE; &#160;&#160;COUNT(*) &#8212;&#8212;&#8212;- &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;14 SQL&#62; ALTER SYSTEM CHECKPOINT; System altered. SQL&#62; TRUNCATE TABLE T_TRUNCATE; Table truncated. SQL&#62; ALTER SYSTEM CHECKPOINT; System altered. &#160; &#160; 在Truncate时只是Segment Header格式化了, 并将Data Object [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp; &nbsp; 不小心Truncate表的事情也是有的, 其中大部份时因为工具连错了库, 从儿跑错了角本. 遇到这种事情而没有备份时怎么办呢? 首先要停止数据库, 将这个表所在的表空间的文件拷贝出来, 因为Oracle在Truncate只时将相应Segment的第一个块格式化掉了, 而后面的都还存在, 到下次用时到才真正地重新格式化. 下面来讲一个Truncate表后进行恢复的例子: </p>
<blockquote class="prefont"><p>
SQL&gt; CREATE TABLE T_TRUNCATE AS SELECT * FROM TAB;</p>
<p>Table created.</p>
<p>SQL&gt; SELECT COUNT(*) FROM T_TRUNCATE;</p>
<p>&nbsp;&nbsp;COUNT(*)<br />
&#8212;&#8212;&#8212;-<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;14</p>
<p>SQL&gt; ALTER SYSTEM CHECKPOINT;</p>
<p>System altered.</p>
<p>SQL&gt; TRUNCATE TABLE T_TRUNCATE;</p>
<p>Table truncated.</p>
<p>SQL&gt; ALTER SYSTEM CHECKPOINT;</p>
<p>System altered.
</p></blockquote>
<p>&nbsp; &nbsp; 在Truncate时只是Segment Header格式化了, 并将Data Object ID换成一个新的值, 我们可以在AUL中用DESC命令来查看: </p>
<blockquote class="prefont"><p>
AUL&gt; desc anysql.t_truncate</p>
<p>Storage(OBJ#=9976 <font color="red">OBJD=9977</font> TS=4 <font color="red">FILE=4 BLOCK=5235</font> CLUSTER=0)<br />
No. SEQ INT Column Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Type<br />
&#8212; &#8212; &#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;&#8212;-<br />
&nbsp;&nbsp;1&nbsp;&nbsp; 1&nbsp;&nbsp; 1 TNAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VARCHAR2(30) NOT NULL<br />
&nbsp;&nbsp;2&nbsp;&nbsp; 2&nbsp;&nbsp; 2 TABTYPE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VARCHAR2(7)<br />
&nbsp;&nbsp;3&nbsp;&nbsp; 3&nbsp;&nbsp; 3 CLUSTERID&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NUMBER
</p></blockquote>
<p>&nbsp; &nbsp; 要恢复这个表的数据, 首先要在AUL中运行SCAN EXTENT命令, 因为Segment Header被格式化了, 所以Extent Map也可能丢失, 而Scan Extent则将扫描整个数据文件并将Extent分配信息写入AULEXT.TXT文件: </p>
<p><span id="more-148"></span></p>
<blockquote class="prefont"><p>
AUL&gt; SCAN EXTENT FILE 4<br />
2006-12-18 21:32:10<br />
2006-12-18 21:32:24
</p></blockquote>
<p>&nbsp; &nbsp; 恢复的关键是要获得这个表原来的Data Object ID, 在这个例子中我在Truncate表后什么也没有做就关闭数据库进行恢复了. 从上面的DESC命令可以看出表的Segment Header是(4,5235), 而新的Data Object ID是9977, 老的Data Object ID我们可以从Segment Header的后面一个数据块中得到, 如果这个表有几个Free List Group, 则可能还要再后面几个块. 用AUL的ORADUMP命令来看一下后面一个块: </p>
<blockquote class="prefont"><p>
AUL&gt; ORADUMP FILE 4 BLOCK 5236<br />
RDBA=0&#215;01001474(4/5236)=16782452,type=0&#215;06,fmt=0xa2,seq=0&#215;02,flag=0&#215;04<br />
<font color="red">seg/obj=0x000026f8=9976</font>,csc=0&#215;0000.0006caf5,itc=3,typ=1 &#8211; DATA<br />
FLG=0&#215;32, fls=0, nxt=0&#215;01001471(4/5233)=16782449<br />
&#8230;&#8230;
</p></blockquote>
<p>&nbsp; &nbsp; 可以看到原来的Data Object ID是9976, 现在可以恢复了, 先不指定原来的Data Object ID试试?</p>
<blockquote class="prefont"><p>
AUL&gt; unload table anysql.t_truncate;<br />
2006-12-18 21:33:37<br />
Unload OBJD=9977 FILE=4 BLOCK=5235 CLUSTER=0 &#8230;<br />
2006-12-18 21:33:37
</p></blockquote>
<p>&nbsp; &nbsp; 接下来指定原来的Data Object ID, 再试试? </p>
<blockquote class="prefont"><p>
AUL&gt; unload table anysql.t_truncate <font color="red">object 9976</font>;<br />
2006-12-18 21:33:45<br />
Unload OBJD=9976 FILE=4 BLOCK=5235 CLUSTER=0 &#8230;<br />
P_MV_FACT_SALES|TABLE<br />
TIME_DIM|TABLE<br />
FACT_SALES|TABLE<br />
MV_FACT_SALES|TABLE<br />
SEG$|TABLE<br />
NUMTEST|TABLE<br />
T_OBJECTS|TABLE<br />
T_LOBTEST|TABLE<br />
T_INCLOB|TABLE<br />
CF_XXK|TABLE<br />
T_TESTDMP|TABLE<br />
T_CLOBDEMO|TABLE<br />
T_BLOBDEMO|TABLE<br />
T_TRUNCATE|TABLE<br />
2006-12-18 21:33:45
</p></blockquote>
<p>&nbsp; &nbsp; 可以看到14条数据全回来了, 当然数据库是复杂的, 如果是一个很大的表, 还是不能保证可以100%恢复的. </p>
<h3  class="related_post_title">Relative Posts:</h3><ul class="related_post"><li>2006/09/18 -- <a href="http://www.anysql.net/aulmydul/aul_recover_truncate.html" title="在AUL/MyDUL中如何恢复被Truncate的表">在AUL/MyDUL中如何恢复被Truncate的表</a> (1)</li><li>2007/02/04 -- <a href="http://www.anysql.net/life/two_recover_requests.html" title="关于AUL数据恢复的两件小事 &#8212; 一口价">关于AUL数据恢复的两件小事 &#8212; 一口价</a> (15)</li><li>2007/01/05 -- <a href="http://www.anysql.net/aulmydul/aul_iot_support.html" title="IOT表中段的命名规律, 以及AUL对IOT的支持">IOT表中段的命名规律, 以及AUL对IOT的支持</a> (0)</li><li>2006/12/25 -- <a href="http://www.anysql.net/aulmydul/aul4_lob_partition.html" title="AUL 4中如何恢复分区表的LOB字段?">AUL 4中如何恢复分区表的LOB字段?</a> (1)</li><li>2006/12/21 -- <a href="http://www.anysql.net/aulmydul/aul4_update_20061221.html" title="AUL 4 Beta程序更新情况 &#8211; 2006.12.21">AUL 4 Beta程序更新情况 &#8211; 2006.12.21</a> (9)</li><li>2006/12/19 -- <a href="http://www.anysql.net/aulmydul/aul4_lob_chunk.html" title="AUL 4现阶段对LOB CHUNK的支持情况">AUL 4现阶段对LOB CHUNK的支持情况</a> (3)</li><li>2006/12/17 -- <a href="http://www.anysql.net/aulmydul/aul4_lob_dmptest.html" title="在10g(Windows)上测试LOB数据的DMP格式恢复">在10g(Windows)上测试LOB数据的DMP格式恢复</a> (0)</li><li>2006/12/17 -- <a href="http://www.anysql.net/aulmydul/aul4_blob_demo.html" title="在10g(Windows)上测试BLOB数据恢复">在10g(Windows)上测试BLOB数据恢复</a> (0)</li><li>2006/12/17 -- <a href="http://www.anysql.net/aulmydul/aul4_clob_demo.html" title="在10g(Windows)上测试CLOB数据恢复">在10g(Windows)上测试CLOB数据恢复</a> (0)</li><li>2006/12/16 -- <a href="http://www.anysql.net/aulmydul/aul4_lob_option.html" title="AUL4中几个和LOB有关的选项">AUL4中几个和LOB有关的选项</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.anysql.net/aulmydul/aul_truncate_recovery.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>在AUL/MyDUL中如何恢复被Truncate的表</title>
		<link>http://www.anysql.net/aulmydul/aul_recover_truncate.html</link>
		<comments>http://www.anysql.net/aulmydul/aul_recover_truncate.html#comments</comments>
		<pubDate>Tue, 19 Sep 2006 06:45:51 +0000</pubDate>
		<dc:creator>anysql</dc:creator>
				<category><![CDATA[AUL/MyDUL]]></category>
		<category><![CDATA[Truncate]]></category>
		<category><![CDATA[数据恢复]]></category>

		<guid isPermaLink="false">http://www.anysql.net/wordpress/uncategorized/%e5%9c%a8aulmydul%e4%b8%ad%e5%a6%82%e4%bd%95%e6%81%a2%e5%a4%8d%e8%a2%abtruncate%e7%9a%84%e8%a1%a8.html</guid>
		<description><![CDATA[&#160; &#160; 最近至少看到二次错误地截断(Truncate)表的例子, 并在网上询问如何恢复, 在这儿我给出AUL/MyDUL的解决方案, 下面是我用的一个测试表: ASQL&#62; DESC TRUNCDEMO NO# NAME&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;NULLABLE TYPE &#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212; &#160;&#160;1 COL1&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; VARCHAR2(20) ASQL&#62; SELECT * FROM TRUNCDEMO; COL1 &#8212;&#8211; ROW 1 ROW 2 2 rows returned. &#160; &#160; 接下来我们来截断表, 其实这个操作只是重新格式化了段头块(Segment Header), 并分配一个新的数据对象号(Data Object ID), 当然空间分配信息也改了, 除非加了重用空间选项(Reuse Storage). 来看一下这个操作的前后变化: ASQL&#62; SELECT DATA_OBJECT_ID, OBJECT_NAME FROM USER_OBJECTS; DATA_OBJECT_ID OBJECT_NAME &#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp; &nbsp; 最近至少看到二次错误地截断(Truncate)表的例子, 并在网上询问如何恢复, 在这儿我给出AUL/MyDUL的解决方案, 下面是我用的一个测试表: </p>
<blockquote class="prefont"><p>
ASQL&gt; DESC TRUNCDEMO</p>
<p>NO# NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULLABLE TYPE<br />
&#8212; &#8212;&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8212;<br />
&nbsp;&nbsp;1 COL1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VARCHAR2(20)</p>
<p>ASQL&gt; SELECT * FROM TRUNCDEMO;</p>
<p>COL1<br />
&#8212;&#8211;<br />
ROW 1<br />
ROW 2</p>
<p>2 rows returned.
</p></blockquote>
<p>&nbsp; &nbsp; 接下来我们来截断表, 其实这个操作只是重新格式化了段头块(Segment Header), 并分配一个新的数据对象号(Data Object ID), 当然空间分配信息也改了, 除非加了重用空间选项(Reuse Storage). 来看一下这个操作的前后变化: </p>
<p><span id="more-54"></span></p>
<blockquote class="prefont"><p>
ASQL&gt; SELECT DATA_OBJECT_ID, OBJECT_NAME FROM USER_OBJECTS;</p>
<p>DATA_OBJECT_ID OBJECT_NAME<br />
&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8211;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="red">13676</font> TRUNCDEMO</p>
<p>1 rows returned.</p>
<p>ASQL&gt; truncate table truncdemo;</p>
<p>Truncate Table Succeed.</p>
<p>ASQL&gt; SELECT DATA_OBJECT_ID, OBJECT_NAME FROM USER_OBJECTS;</p>
<p>DATA_OBJECT_ID OBJECT_NAME<br />
&#8212;&#8212;&#8212;&#8212;&#8211; &#8212;&#8212;&#8212;&#8211;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="red">13677</font> TRUNCDEMO</p>
<p>1 rows returned.
</p></blockquote>
<p>&nbsp; &nbsp; 由于在System表空间中已经记录了新的信息, 因此用当前的System信息是不能恢复过来的,在AUL/MyDUL中可以当作<a href="http://www.anysql.net/aulmydul/aul_nosystem_recovery.html">没有System时的情况</a>来处理,在下面的命令中, 我们用Truncate后的数据对象号就不能进行恢复, 而使用Truncate以前的就可以, 当然空间不能被重新利用了是恢复的前提.</p>
<blockquote class="prefont"><p>
AUL&gt; unload object 13676 column varchar file 4;<br />
2006-09-18 22:38:58<br />
ROW 1<br />
ROW 2<br />
2006-09-18 22:39:04<br />
AUL&gt; unload object 13677 column varchar file 4;<br />
2006-09-18 22:39:10<br />
2006-09-18 22:39:10<br />
AUL&gt;
</p></blockquote>
<p>&nbsp; &nbsp; 因此在意外发生Truncate后, 如果没有备份可以恢复, 首先要做的事是备份一下当前的文件, 免得空间被重用. 而Truncate之前的数据对象号在AUL/MyDUL中是很容易找出来的. 到此已经说明了如何恢复Truncate表了. </p>
<h3  class="related_post_title">Relative Posts:</h3><ul class="related_post"><li>2006/12/18 -- <a href="http://www.anysql.net/aulmydul/aul_truncate_recovery.html" title="在AUL中如何轻松恢复TRUNCATE的表?">在AUL中如何轻松恢复TRUNCATE的表?</a> (2)</li><li>2007/02/04 -- <a href="http://www.anysql.net/life/two_recover_requests.html" title="关于AUL数据恢复的两件小事 &#8212; 一口价">关于AUL数据恢复的两件小事 &#8212; 一口价</a> (15)</li><li>2007/01/05 -- <a href="http://www.anysql.net/aulmydul/aul_iot_support.html" title="IOT表中段的命名规律, 以及AUL对IOT的支持">IOT表中段的命名规律, 以及AUL对IOT的支持</a> (0)</li><li>2006/12/25 -- <a href="http://www.anysql.net/aulmydul/aul4_lob_partition.html" title="AUL 4中如何恢复分区表的LOB字段?">AUL 4中如何恢复分区表的LOB字段?</a> (1)</li><li>2006/12/21 -- <a href="http://www.anysql.net/aulmydul/aul4_update_20061221.html" title="AUL 4 Beta程序更新情况 &#8211; 2006.12.21">AUL 4 Beta程序更新情况 &#8211; 2006.12.21</a> (9)</li><li>2006/12/19 -- <a href="http://www.anysql.net/aulmydul/aul4_lob_chunk.html" title="AUL 4现阶段对LOB CHUNK的支持情况">AUL 4现阶段对LOB CHUNK的支持情况</a> (3)</li><li>2006/12/17 -- <a href="http://www.anysql.net/aulmydul/aul4_lob_dmptest.html" title="在10g(Windows)上测试LOB数据的DMP格式恢复">在10g(Windows)上测试LOB数据的DMP格式恢复</a> (0)</li><li>2006/12/17 -- <a href="http://www.anysql.net/aulmydul/aul4_blob_demo.html" title="在10g(Windows)上测试BLOB数据恢复">在10g(Windows)上测试BLOB数据恢复</a> (0)</li><li>2006/12/17 -- <a href="http://www.anysql.net/aulmydul/aul4_clob_demo.html" title="在10g(Windows)上测试CLOB数据恢复">在10g(Windows)上测试CLOB数据恢复</a> (0)</li><li>2006/12/16 -- <a href="http://www.anysql.net/aulmydul/aul4_lob_option.html" title="AUL4中几个和LOB有关的选项">AUL4中几个和LOB有关的选项</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.anysql.net/aulmydul/aul_recover_truncate.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
