`
jiaoronggui
  • 浏览: 1302514 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
博客专栏
B7c2eb31-a8ea-3973-a517-d00141f39b89
项目管理软件-redmin...
浏览量:115182
4a63e153-250f-30f6-a051-97cfc67cb3d3
IT职业规划
浏览量:197636
社区版块
存档分类
最新评论

create index注意n如果是大表建立索引,切记加上ONLINE参数

阅读更多

这几天在做数据库的优化,有个2亿记录的表,发现需要添加一个联合索引,结果就采用普通的create index index_name

on tablename (entp_id,sell_date),结果悲剧了,把所有的DML语句都阻塞了,导致系统不能正常使用,还好是晚上10点,用户不是非常多,1个小时候,索引结束,阻塞解决;

      上网查了一下,如果加上 online参数后,就可以在线做索引,而不需要阻塞所有的DML语句,血的教训,拿出来与各位共勉,具体online与不加online区别如下:

 

 

1. DML操作对create index 的影响。 如果在create的时候,有其他的进程在对这个index 所对应的数据进行DML操作,create会受影响:

SQL> create table test (id number, name varchar2(20));

Table created.


--- 然后重新开一个session:
SQL> insert into test values (1,'lms');

1 row created.

<no commit>

SQL> create index t1 on test(id);
create index t1 on test(id)
*
ERROR at line 1:
ORA-00054: resource busy and acquire with NOWAIT specified

2. 加online这个参数,这个参数加上以后,除了create过程中index 保持online状态,Oracle还会在create index之前等待所有DML操作结束,然后得到DDL锁,开始create.
SQL> create index t1 on test(id) online;
<hold before commit>
<after commit>

SQL> commit;

Commit complete.

Index altered.

---- 如果不commit,上面的操作就会一直hold。

所以以后create索引和rebuild索引的时候最好加上online。

0
2
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics