怎么有效的drop 或者truncate 有大量extents的table?
来源于:
How To Efficiently Drop (or Truncate) A Table With Many Extents (文档 ID 68836.1)
目的:
本文描述了为什么一个用户进程在drop 了一个含有大量extents的table之后消耗大量的cpu资源。并给出一个潜在的workaround以阻止该问题的发生。本质来说,CPU被用于对extents的管理(manipulate),比如moving used extents(uet$)到 free extents(fet$).在某种情况中,it may be possible to regulate this CPU activity.
适用范围:
本文协助DBA处理 drop 掉很多extents的表。
相关的文章:
Note:61997.1 SMON - Temporary Segment Cleanup and Free Space Coalescing
永久对象的清理
如果一个永久对象(table)是由 很多extents组成的,并且该object被drop,drop 该object的用户进程将会消耗很多的CPU资源,
这是不可避免的事实(an inescapable fact)。但是,基于一些远见卓识(with some forethought),
可以减轻(mitigate)CPU的使用(and hence the knock-on effect on other users of system resources)
1. Identify, but do NOT drop the table
2.使用 REUSE STORAGE子句来truncate 该表。这样会很快,因为相关的extents不会被释放。高水位线(highwater mark)被简单的调整到segment header block
3. 使用KEEP子句来释放该table中未使用的extents。这是本步骤的关键所在--通过指定table中有多少extent不会被释放,你可以控制有多少extents被释放
举例:
o. Table BIGTAB is 2Gb in size and consists of 262144 8Kb extents
o. There is little CPU power available, and (from past experience) it is known that dropping an object of this number of extents can take days
o. The system is quiet at night times (no other users or batch jobs)
在上面的例子中,table可以分为几个阶段在几个晚上被drop
1. Truncate the table, specifying the REUSE STORAGE clause:
SQL> TRUNCATE TABLE BIGTAB REUSE STORAGE;
2. If it takes 3 days (72 hours) to drop the table, spread this out over
6 nights i.e. drop 1/3 Gb per night. This can be achieved in 6 (nightly)
steps as follows:
注意:If the table only needed truncating, no drop statement is needed here.
Night 1: SQL> ALTER TABLE BIGTAB DEALLOCATE UNUSED KEEP 1707M; (2Gb*5/6) Night 2: SQL> ALTER TABLE BIGTAB DEALLOCATE UNUSED KEEP 1365M; (2Gb*4/6) Night 3: SQL> ALTER TABLE BIGTAB DEALLOCATE UNUSED KEEP 1024M; (2Gb*3/6) Night 4: SQL> ALTER TABLE BIGTAB DEALLOCATE UNUSED KEEP 683M; (2Gb*2/6) Night 5: SQL> ALTER TABLE BIGTAB DEALLOCATE UNUSED KEEP 341M; (2Gb*1/6) Night 6: SQL> DROP TABLE BIGTAB;
相同的方法也适用于LOB segments和index segment
SQL> ALTER TABLE MODIFY LOB () DEALLOCATE UNUSED KEEP M; SQL> ALTER INDEX DEALLOCATE UNUSED KEEP M;
警告(caveats):
o.如果你无意之间使用了drop 命令,本方法就不适用了。这是因为,drop table 会首先convert segment到一个临时segment,and only then start cleaning up the now temporary segment‘s extents.Thus, if the drop is interrupted, the temporary segment will now be cleaned up by SMON.
o.This method will only work for table, lob and index segment types.
o.This method will not work for segments bigger than 4gb in size due to unpublished bug:
1190939 -- ORA-3277 WHEN ISSUING AN ALTER TABLE DEALLOCATE UNUSED > 4G (fixed in 10g and higher)