Oracle Nologging+Append注意事项

查看创建的表是否为nologging  user_tables.logging字段。

   如果直接 加载的表上有索引,Oracle不会像加载数据的方式那样来处理索引的数据,但是它同样需要维护一个索引,这个成本很高,同时会生成很多的redo。

   所以当使用直接加载时,通常是针对一些数据量非常大的表。如果这些表存在索引,将会带来很大的性能影响,这时可以考虑先将索引disable或者drop掉,等加载数据后,之后在重新建立索引。 

创建索引指定nologging:

create index idx_object_id on idx_test(object_id) nologging;

 

使用insert append的缺点在于仅会向高水位线之上的块进行插入,会忽略高水位线下的空闲块,所以 append会提高高水位线。

insert append时在表上加“ 6”类型的 Exclusive锁,即排它锁 ,为表级锁 ,会阻塞表上的所有 DML语句。因此在有业务运行的上传环境下要慎重使用。

测试:

SYS@prod>insert /*+APPEND*/ into test select * from test;

在其他会话查看锁定对象情况:

SYS@prod>select object_id,session_id,locked_mode from v$locked_object;

 OBJECT_ID SESSION_ID LOCKED_MODE

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

     88905   125   6

  有关Append的其他错误:

ORA-12938 错误
如果直接 路径加载的事务未提交或回滚,则同一个会话无法访问被修改的表(报ORA-12838: cannot read/modify an object after modifying it in parallel ),非同一个会话可以访问。 

SYS@prod>insert /*+APPEND*/ into test select * from test;

5566720 rows created.

SYS@prod>select count(*) from test;

select count(*) from test

*

ERROR at line 1:

ORA-12838: cannot read/modify an object after modifying it in parallel


请使用浏览器的分享功能分享到微信等