【翻译自mos文章】怎么有效的drop 或者truncate 有大量extents的table?

本文提供了处理包含大量extents的table的drop或truncate操作的策略,旨在减少CPU资源的消耗。通过使用REUSESTORAGE子句进行快速truncate,指定KEEP子句释放未使用的extents,并在非高峰时段分阶段执行drop操作,从而减轻系统资源的压力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

怎么有效的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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值