ORACLE通过锁和闩的方式实现了并发控制,v$lock 视图列出了数据库中当前拥有的锁以及未完成的锁请求。当发觉有session处于等待事件时 ,可以通过v$lock查询信息。

v$lock中的常用列有以下列:

sid:持有锁的会话SID,通常与v$session关联。

type:锁的类型,其中TM表示表锁或DML锁,TX表示行锁或事务锁,UL表示用户锁。我们主要关注TX和TM两种型的锁,其它均为系统锁,会很快自动释放,不用关注。当 Oracle执行 DML 语句时,系统自动在所要操作的表上申请 TM 类型的锁。当 TM锁获得后,系统再自动申请 TX 类型的锁,并将实际锁定的数据行的锁标志位进行置位。TM 锁包括了SS 、 SX、 S 、X 等多种模式,在数据库中用 0 -6 来表示。不同的 SQL 操作产生不同类型的 TM锁。

lmode:会话保持的锁的模式。

0=None;

1=Null ;

2=Row-S (SS,行级共享锁,其他对象只能查询这些数据行),sql操作有select for update、lock for update、lock row share;

3=Row-X (SX,行级排它锁,在提交前不允许做DML操作),sql操作有insert、update、delete、lock row share;

4=Share(共享锁),sql操作有create index、lock share;

5=S/Row-X (SSX,共享行级排它锁),sql操作有lock share row exclusive;

6=Exclusive(排它锁),alter table、drop table、drop index、truncate table、look exclusive等DDL

ID1,ID2:  ID1,ID2的取值含义根据type的取值而有所不同,对于TM 锁ID1表示被锁定表的object_id 可以和dba_objects视图关联取得具体表信息,ID2 值为0;对于TX 锁ID1以十进制数值表示该事务所占用的回滚段号和事务槽slot number号,其组形式: 0xRRRRSSSS,RRRR=RBS/UNDO NUMBER,SSSS=SLOT NUMBER,ID2 以十进制数值表示环绕wrap的次数,即事务槽被重用的次数。实际上这两个字段构成了事务在回滚段中的位置。

对于alter index rebuild online引发的的锁,下面我们来验证一下

另外打开一个服务端口,对索引idx_a1 做rebuild online 操作,发现索引的rebuild操作迟迟不能完成。这个时候需要通过第三个窗口查询一下v$lock,发现锁的模式是TM,通过hash值获得sqltext内容正是我们的索引rebuild onlin操作

说明在做rebuild online操作,会等待它之前未提交dml操作,直到dml操作释放资源

下面是MOS上给出的解释,原理很重要,认真看完。

========

- Online Index rebuild takes a long time.

- ONLINE INDEX REBUILD SCANS THE BASE TABLE AND NOT THE INDEX

Symptoms:

=========

Performance issues while rebuilding very large indexes.

- The offline rebuilds of their index is relatively quick -finishes in 15 minutes.

- Issuing index rebuild ONLINE statement => finishes in about an hour.

- This behavior of ONLINE index rebuilds makes it a non-option for large tables

as it just takes too long to scan the table to rebuild the index. The offline may not be feasible due to due to the 24/7 nature of the database.

- This may be a loss of functionality for such situations.

- If we attempt to simultaneously ONLINE rebuild the same indexes we may encounter hanging behavior indefinitely (or more than 6 hours).

DIAGNOSTIC ANALYSIS:

--------------------

We can trace the sessions rebuilding the indexes with 10046 level 12.

Comparing the IO reads for the index-rebuild and the index-rebuild-online reveals the following:

-ONLINE index rebuilds

It scans the base table and it doesn't scan the blocks of the index.

-OFFLINE index rebuilds

It scans the index for the build operation.

- This behaviour is across all versions.

Cause

Cause/Explanation

=============

When you rebuild index online,

- it will do a full tablescan on the base table.

- At the same time it will maintain a journal table for DML data, which has

changed during this index rebuilding operation.

So it should take longer time, specially if you do lots of DML on the same table,while rebuilding index online.

On the other hand, while rebuilding the index without online option, Oracle will grab the index in X-mode and rebuild a new index segment by selecting the data from the old index. So here we are

- not allowing any DML on the table hence there is no journal table involved

- and it is doing an index scan

Hence it will be pretty fast.

Fix

Solution/Conclusion:

===========

- The ONLINE index rebuild reads the base table, and this is by design.

- Rebuilding index ONLINE is pretty slow.

- Rebuilding index offline is very fast, but it prevents any DML on the base table.

参考博客:

http://blog.itpub.net/26770925/viewspace-1293245/

oracle rebuild online,ORACLE alter index rebuild online 操作产生的锁相关推荐

  1. oracle中alter index,oracle alter index rebuild online和alter index rebuild的區別

    本文用10046事件來解析alter index rebuild與alter index rebuild online的區別 alter index rebuild online實質上是掃描表而不是掃 ...

  2. 重建索引:ALTER INDEX..REBUILD ONLINE vs ALTER INDEX..REBUILD

    什么时候需要重建索引1. 删除的空间没有重用,导致 索引出现碎片 2. 删除大量的表数据后,空间没有重用,导致 索引"虚高" 3.索引的 clustering_facto 和表不一 ...

  3. oracle index alter,Oracle alter index rebuild 一系列问题

    在ITPUB  论坛上看到的一个帖子,很不错.根据论坛的帖子重做整理了一下.  原文链接如下: alter index rebuild online引发的血案 一. 官网说明 在MOS 上的一篇文章讲 ...

  4. oracle rebuild online,alter index rebuild

    Oracle alter index rebuild 说明[日期:2011-06-12]来源:Linux社区 作者:tianlesoftware[字体:大中小] 一.官网说明 在MOS 上的一篇文章讲 ...

  5. mysql alter index rebuild_Oracle alter index rebuild 说明

    一.官网说明 在MOS上的一篇文章讲到了rebuild online和offline的区别: Index Rebuild Is Hanging Or Taking Too Long [ID 27276 ...

  6. ALTER INDEX Rebuild Reorganize 索引 重建 重组 碎片率

    转载于:https://www.cnblogs.com/Microshaoft/archive/2011/07/12/2104753.html

  7. Oracle Partition维护之 - tabel / index分区命令

    今天在看CBO书的时候看到跨子分区表查询的执行计划时,对分区表的partition exchange loading,查询到此片博文,转来使用 分区表维护的常用命令: ALTER TABLE -- D ...

  8. oracle groupq by,oracle group by 性能优化

    慕田峪9158850 (1) 选择最有效率的表名顺序(只在基于规则的优化器中有效):ORACLE的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving ...

  9. oracle高压水位线,Oracle 高水位线详解(HWM)

    HWM:高水位线, 可用空间与已用空间的分界线,标记着段空间使用情况. 所有的oracle段(segments,在此,为了理解方便,建议把segment作为表的一个同义词) 都有一个在段内容纳数据的上 ...

最新文章

  1. python 区域和检索_304. 二维区域和检索(Python)
  2. php 清除之前echo_PHP入门读书笔记(三): 常量和变量
  3. APP元素事件操作API
  4. Windows安装.net Framework时安装不上,提示已处理证书链,但是在不受信任提供程序信任的根证书中终止
  5. Hugo中文文档 快速开始
  6. Unity 2D 跑酷道路动起来
  7. 【SQLAlchemy】SQLAlchemy技术文档(中文版)(上)
  8. 8 行代码用Python画一个中国地图
  9. 小程序input获得焦点触发_小程序学习(三)
  10. gif跟随ProgressBar一起动/pk进度条gif特效
  11. 南邮物联网学院计算机考研,研友分享南京邮电大学物联网学院两个专业的一点看法...
  12. 计算机启动硬盘引导过程,如何重建mbr|硬盘重建主引导记录(mbr)步骤
  13. SAP中通过放大成本核算批量的方式解决由采购金额过小导致的”成本构成分解为零”的问题
  14. 结构化随机森林 代码说明
  15. 【ISO】Windows10系统ISO镜像怎么从微软官网下载?
  16. 机器人开发--二维激光SLAM介绍
  17. mqtt服务器(mosquitto)测试环境的搭建
  18. 微信好友突破10000人,节跳动即将取消饮料补贴福利!!
  19. Ubuntu16.04笔记本 安装R RStudio
  20. 《经济学是什么》精髓:如何用经济学家的眼光理解个人选择和市场经济?

热门文章

  1. Java实现Excel批量导入数据
  2. 系统性综述:特征点检测与匹配
  3. 详述光波分复用(WDM)技术
  4. [机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心
  5. 支付计算机维护费分录,税控技术维护费会计分录是什么
  6. windows 搭建代理服务器 - Fiddler
  7. 低代码可以做什么?以织信informat这个平台为例说说
  8. DockerHub入门
  9. 鹏业软件打开图纸显示内存不足问题解决
  10. SSH三大框架笔面试总结