使用ASSM表空间(默认模式)的时候,在dss系统中确实会出现truncate很慢的现象,但是他不会100%重现,得看概率。通过sql trace(对任何v$sysstat看起来资源消耗很低的情况,都可以通过sql trace找到根本原因,所以sql trace是个用来分析但是未必能够帮助解决问题的必备工具)可以看到内部时间如何消耗的。对于truncate,因为目前我们没有直接遇到过,就不分析了,但是在FDA的时候遇到了,顺便搜索了下(FDA是其他原因,见本博客其他帖子),truncate本身慢的原因如下:

Here’s one that started off with a tweet from Kevin Closson, heading towards a finish that shows some interesting effects when you truncate large objects that are using ASSM. To demonstrate the problem I’ve set up a tablespace using system allocation of extents and automatic segment space management (ASSM).  It’s the ASSM that causes the problem, but it requires a mixture of circumstances to create a little surprise.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
create
     tablespace test_8k_auto_assm
     datafile    -- OMF
     SIZE 1030M
     autoextend off
     blocksize 8k
     extent management local
     autoallocate
     segment space management auto
;
create table t1 (v1 varchar2(100)) pctfree 99 tablespace test_8k_auto_assm storage(initial 1G);
insert into t1 select user from dual;
commit;
alter system flush buffer_cache;
truncate table t1;

I’ve created a table with an initial definition of 1GB, which means that (in a clean tablespace) the autoallocate option will jump straight to extents of 64MB, with 256 table blocks mapped per bitmap block for a total of 32 bitmap blocks in each 64MB extent. Since I’m running this on 11.2.0.4 and haven’t included “segment creation immediate” in the definition I won’t actually see any extents until I insert the first row.

So here’s the big question – when I truncate this table (using the given command) how much work will Oracle have to do ?

Exchanging notes over twitter (140 char at a time) and working from a model of the initial state, it took a little time to get to understand what was (probably) happening and then produce this silly example – but here’s the output from a snapshot of v$session_event for the session across the truncate:

1
2
3
4
5
6
7
8
9
Event                                             Waits   Time_outs           Csec    Avg Csec    Max Csec
-----                                             -----   ---------           ----    --------    --------
local write wait                                    490           0          83.26        .170          13
enq: RO - fast object reuse                           2           0         104.90      52.451         105
db file sequential read                              47           0           0.05        .001           0
db file parallel read                                 8           0           0.90        .112           0
SQL*Net message to client                            10           0           0.00        .000           0
SQL*Net message from client                          10           0           0.67        .067         153
events in waitclass Other                             2           0           0.04        .018         109

The statistic I want to highlight is the number recorded against “local write wait”: truncating a table of one row we wait for 490 blocks to be written! We also have 8 “db file parallel read”  waits which, according to a 10046 trace file, were reading hundreds of blocks. (I think the most significant time in this test – the RO enqueue wait – may have been waiting for the database writer to complete the work needed for an object checkpoint, but I’m not sure of that.)

The blocks written were the space management bitmap blocks for the extent(s) that remained after the truncate – even the ones that referenced extents above the high water mark for the table. Since we had set the tables initial storage to 1GB, we had a lot of bitmap blocks. At 32 per extent and 16 extents (64MB * 16 = 1GB) we might actually expect something closer to 512 blocks, but actually Oracle had formatted the last extent with only 8 space management blocks. and the first extent had an extra 2 to cater for the level 2 bitmap lock and segment header block giving: 32 * 15 + 8 + 2 = 490.

As you may have seen above, the impact on the test that Kevin was doing was quite dramatic – he had set the initial storage to 128GB (lots of bitmap blocks), partitioned the table (more bitmap blocks) and was running RAC (so the reads were running into waits for global cache grants).

I had assumed that this type of behaviour happened only with the “reuse storage” option of the truncate command: and I hadn’t noticed before that it also appeared even if you didn’t reuse storage – but that’s probably because the effect applies only to the bit you keep, which may typically mean a relatively small first extent. It’s possible, then, that in most cases this is an effect that isn’t going to be particularly visible in production systems – but if it is, can you work around it ? Fortunately another tweeter asked the question “What happens if you ‘drop all storage?'”

truncate有三个选项,如下:

  • DROP STORAGE, the default option, reduces the number of extents allocated to the resulting table to the original setting for MINEXTENTS. Freed extents are then returned to the system and can be used by other objects.

  • DROP ALL STORAGE drops the segment. In addition to the TRUNCATE TABLE statement, DROP ALL STORAGE also applies to the ALTER TABLE TRUNCATE (SUB)PARTITION statement. This option also drops any dependent object segments associated with the partition being truncated.

    DROP ALL STORAGE is not supported for clusters.

    Note:

    This functionality is available with Oracle Database 11g release 2 (11.2.0.2).

    TRUNCATE TABLE emp DROP ALL STORAGE;
    
  • REUSE STORAGE specifies that all space currently allocated for the table or cluster remains allocated to it. For example, the following statement truncates the emp_dept cluster, leaving all extents previously allocated for the cluster available for subsequent inserts and deletes:

    TRUNCATE CLUSTER emp_dept REUSE STORAGE;

Here’s the result from adding that clause to my test case:

1
2
3
4
5
6
7
8
Event                                             Waits   Time_outs           Csec    Avg Csec    Max Csec
-----                                             -----   ---------           ----    --------    --------
enq: RO - fast object reuse                           1           0           0.08        .079           0
log file sync                                         1           0           0.03        .031           0
db file sequential read                              51           0           0.06        .001           0
SQL*Net message to client                            10           0           0.00        .000           0
SQL*Net message from client                          10           0           0.56        .056         123
events in waitclass Other                             3           0           0.87        .289         186

Looking good – if you don’t keep any extents you don’t need to make sure that their bitmaps are clean. (The “db file sequential read” waits are almost all about the data dictionary, following on from my “flush buffer cache”).

Footnote

The same effect appears in 12.1.0.2

Footnote 2

It’s interesting to note that the RO enqueue wait time seems to parallel the local write wait time: perhaps a hint that there’s some double counting going on. (To be investigated, one day).

Footnote 3 (June 2018)

The same effect appears in 12.2.0.1

转载于:https://www.cnblogs.com/zhjh256/p/9806307.html

truncate table很慢之enq: RO - fast object reuse和local write wait等待分析相关推荐

  1. oracle enq ta,【案例】Oracle等待事件event enq: KO - fast object checkpoint解决办法

    [案例]Oracle等待事件event enq: KO - fast object checkpoint解决办法 时间:2016-11-03 10:11   来源:Oracle研究中心   作者:HT ...

  2. Oracle truncate table 与 delete tabel的区别(转)

    Oracle truncate table 与 delete tabel的区别(转) 一. 1.delete产生rollback,如果删除大数据量的表速度会很慢,同时会占用很多的rollback se ...

  3. 深入解析TRUNCATE TABLE – 手工修复和验证过程

    关注我们获得更多精彩 作者 | 李翔宇,云和恩墨西区交付技术顾问,长期服务移动运营商行业客户,精通 oracle 性能优化,故障诊断,特殊恢复领域. 摘要 众所周知,truncate table 是一 ...

  4. Truncate Table 删除表内容避免产生过多日志

    数据库每天在进行频繁操作和记录,LOG文件会特别大且增长的比较快,有时候一天就5000M,每天删除一次也很不方便.有没有方法能避免生成日志或不产生日志呢?不产生日志的方法目前我还没找到,但我们在平常的 ...

  5. SQL Server数据恢复准备之TRUNCATE TABLE理解

    当truncate table发生时,如何进行恢复,相信大部分人都会选择通过还原备份到truncate table前,然后将数据重新导入正式表中. 那么在SQL Server中是不是真的只有这种方法呢 ...

  6. truncate table AND rename table + create table测试

    处理线上项目遗留的垃圾表(俗称阑尾工程)时会出现: 1.数据不需要了,但是还很大,可以找个空闲的时间直接truncate掉 2.代码还没有清理,数据还有写入,他们还是需要表结构的,你要是rename, ...

  7. mysql truncate 大表_MySQL删除大表时潜在的问题(drop table,truncate table)

    case1,删除大表时,因为清理自适应hash索引占用的内容导致的MySQL服务挂起 case2,大表的随意Drop或者truncate导致MySQL服务的挂起 按照本文中的结论就是 MySQL5.6 ...

  8. mysql 中 使用truncate table XXXX 的时候出现 DROP command denied to user 'xxx' for table ' YYY的问题解决

    最近在使用全量更新数据的时候想使用truncate table的时候,在测试环境没有任何问题,但是在生产线上环境出现了如下的错误: drop command denied to XXXX....的错误 ...

  9. oracle truncate写法,Oracle Truncate Table

    oracle函数 的 Oracle Truncate Table 在本教程中,您将学习如何使用Oracle TRUNCATE TABLE语句更快更有效地从表中删除所有数据(也叫截断表). Oracle ...

最新文章

  1. 一文带你搞懂 MySQL 分区!
  2. 学生课程表管理系统——stage 1
  3. 并发编程下的性能定律(翻译)
  4. SAP UI5的support Assistant
  5. Java和iText导出pdf文档
  6. android接口类命名规范_超全面的UI基础设计规范来啦,还不收藏 ~
  7. xheditor富文本框 存值与展示问题
  8. golang map的无序性验证
  9. JDK 8 十大新特性详解
  10. java编程工具 初学者_面向初学者的Java编程在线课程
  11. setup.s (读核笔记系列)
  12. java web基础 --- URL重定向Filter
  13. fiddler 安装配置,连接手机,抓包QQ小程序
  14. iperf3 for Linux
  15. 电脑常见故障及解决方法
  16. ABB机器人紧凑型控制柜内部结构(图)
  17. duxcms1.0 默认主题分析
  18. 计算机显卡故障,电脑显卡有什么故障 电脑显卡常见故障汇总
  19. linux自定义oem分区,怎么样把oem分区里的数据移到虚拟机的硬盘里?
  20. 数据可视化----常用图表样式

热门文章

  1. php当月1号怎么获取,php获取下月1号和月底最后一天的时间
  2. 华为如何显示我的电脑连接到服务器地址,怎么查电脑的服务器连接地址
  3. 嵌入式图形解决方案升级!RT-Thread Smart成功支持ARM Mali GPU
  4. 关于图灵机的妙文(3)——图灵机杂思(rev#2)(刘未鹏)
  5. svm分类器_使用放射学机器学习分类器区分胶质母细胞瘤与孤立性脑转移瘤
  6. sql注入危害利用及防护详解+sqlmap使用
  7. linux自动清理磁盘日志的一种方案
  8. 早稻田大学国际文学馆(村上春树图书馆)正式开馆
  9. 文件指纹修改工具 Hash Modifier
  10. source insight 4.0 代码函数变量符号高亮