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
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值