Oracle 10.2.0.4 , Linux AS 5.3
truncate会产生redo , undo , 是修改数据字典产生的,不是删除数据产生的。
truncate操作会做什么 : 移动HWM,释放extent,重新生成data_object_id。truncate之所以比比delete快,是因为它根本不需要删除数据。但是在实际中我们经常碰到truncate很慢的情况,实际上它比我们想象的要复杂。 在truncate之前,CKPT必须搜索整个buffer cache,把这个object的dirty buffer全部写回磁盘(这个操作在10g有了改进) 。
Truncate操作只是改了一下数据字典上的一部份信息, 另外将重新分配一个Extent, 并获得一个新的Data Object ID, 并修改Segment Header中的信息, 在数据文件中的数据部份没有作什么修改, 象以前的DOS下删除文件一样, 有undel工具可以将文件找回来, 主要是因为磁盘中存放文件的部份没有修改. 因此对于Truncate操作如果我们知道以前的Data Object ID, 然后在数据文件中是可以重新找回数据的. Truncate和Windows上删除文件类似,更改的只是Segment Header和Inode表、 如果空间没有重用,数据就仍然在那里存在 ; 很多系统在作删除操作的时候都只是做一个标志位,不会去作给磁盘填0那样昂贵的操作 。
Truncate不删除数据,redo中只会记录这个操作而不会有大量数据的log记录 ,所以redo 会生成很少。
SQL> startup nomount
ORACLE instance started.
Total System Global Area 1.6106E+10 bytes
Fixed Size 2112048 bytes
Variable Size 2097153488 bytes
Database Buffers 1.3992E+10 bytes
Redo Buffers 14663680 bytes
SQL> alter database mount standby database;
Database altered.
SQL> alter database open read only ;
Database altered.
SQL> select count(*) from dfms.SYS_D_ERROR_TRACE ;
COUNT(*)
----------
5711786
在STANDBY上恢复归档后发现(这个表上只有truncate删除没有delete) :
ORA-00279: change 3235731736 generated at 03/15/2010 14:21:16 needed for thread
1
ORA-00289: suggestion : /ocfs_data/mxdell/arch/1_11335_703296551.arc
ORA-00280: change 3235731736 for thread 1 is in sequence #11335
ORA-00278: log file '/ocfs_data/mxdell/arch/1_11334_703296551.arc' no longer
needed for this recovery
ORA-00279: change 3235731783 generated at 03/15/2010 14:21:18 needed for thread
3
ORA-00289: suggestion : /ocfs_data/mxdell/arch/3_10950_703296551.arc
ORA-00280: change 3235731783 for thread 3 is in sequence #10950
ORA-00278: log file '/ocfs_data/mxdell/arch/3_10949_703296551.arc' no longer
needed for this recovery
ORA-00308: cannot open archived log
'/ocfs_data/mxdell/arch/3_10950_703296551.arc'
ORA-27037: unable to obtain file status
Linux-x86_64 Error: 2: No such file or directory
Additional information: 3
SQL>
SQL> alter database open read only;
Database altered.
SQL> select count(*) from dfms.SYS_D_ERROR_TRACE ;
COUNT(*)
----------
172598
SQL>
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/35489/viewspace-629545/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/35489/viewspace-629545/