关于Oracle的44951事件

最近有同事遇到某客户数据库产生大量阻塞,等待事件为:enq HW – contention,最开始采用不断杀会话的方式,效果不好,问题一直高频反复。进一步确认SQL是大量的insert,且插入的表中含有LOB字段,根据经验最终采用设置44951 event缓解了该问题。

具体关于Oracle的44951事件,可参考Maclean的文章:

这篇文章中采用的设置方法是:

alter system set events '44951 trace name context forever, level 1024';

需要注意的是,这种设置方法在重启数据库后就会失效,若需要重启后永久生效,需设置event:

alter system set event='44951 trace name context forever, level 1024' scope=spfile;

但说到这里就需要深入了解下event和events的区别,这里大概测试总结有如下区别:

  • 1.events立即生效,重启数据库后消失
  • 2.events无法直接通过show parameter event查看
  • 3.event后面必须有等号,重启数据库后生效,可通过show parameter event查看
  • 4.event需要注意不要覆盖掉之前的event设置,如果这个知识点不理解很容易产生误操作,需要特别注意

补充说明:
比如在11g的最佳实践中,通常已经设置10949和28401event:

alter system set event='28401 trace name context forever,level 1','10949 trace name context forever,level 1' sid='*' scope=spfile;

所以如果有需求额外设置44951 event,就需要将之前的也写上(否则就会覆盖):

alter system set event='28401 trace name context forever,level 1','10949 trace name context forever,level 1','44951 trace name context forever,level 1024' sid='*' scope=spfile;

events设置的值如何查看?使用下面的脚本(注意循环的范围要包含要查询的events):

set serveroutput on

declare
event_level number;
begin
for i in 10000..50000 loop
sys.dbms_system.read_ev(i,event_level);
if (event_level > 0) then
dbms_output.put_line('Event '||to_char(i)||' set at level '||
to_char(event_level));
end if;
end loop;
end;
/

查询结果类似如下:

Event 10949 set at level 1
Event 28401 set at level 1
Event 44951 set at level 1024

附:Maclean使用的测试用例:

create user maclean identified by maclean;
grant resource, connect, dba to maclean;
conn maclean/maclean

CREATE TABLE "MACLEAN_LOB" ( "T1" VARCHAR2(200) NOT NULL , "T2" CLOB, "T3" CLOB)  tablespace users
    LOB ("T2") 
    STORE AS  ( TABLESPACE "USERS" CHUNK 16K PCTVERSION 50 CACHE ) 
    LOB ("T3") 
    STORE AS  ( TABLESPACE "USERS" CHUNK 16K PCTVERSION 50 CACHE );

select segment_space_management from dba_tablespaces where tablespace_name='USERS';

exec dbms_workload_repository.create_snapshot;

--开3个进程并发插入LOB表
begin
for i in 1..10000 loop
 insert into maclean.maclean_lob values ('ABC',rpad('Z',32000,'L'),rpad('Z',32000,'L'));
 end loop;
 commit;
 end;
 /

exec dbms_workload_repository.create_snapshot;
select bytes/1024,segment_name from dba_segments where segment_name in (select segment_name from dba_lobs where table_name='MACLEAN_LOB' and owner='MACLEAN');
truncate table maclean.maclean_lob;
select bytes/1024,segment_name from dba_segments where segment_name in (select segment_name from dba_lobs where table_name='MACLEAN_LOB' and owner='MACLEAN');

alter system flush buffer_cache;
alter system flush shared_pool;

alter system set events '44951 trace name context forever, level 1024';

exec dbms_workload_repository.create_snapshot;

--开3个进程并发插入LOB表
begin
for i in 1..10000 loop
 insert into maclean.maclean_lob values ('ABC',rpad('Z',32000,'L'),rpad('Z',32000,'L'));
 end loop;
 commit;
 end;
 /  

exec dbms_workload_repository.create_snapshot;

select bytes/1024,segment_name from dba_segments where segment_name in (select segment_name from dba_lobs where table_name='MACLEAN_LOB' and owner='MACLEAN');

以上可以看到虽然设置了44951 level 1024,但并不会因为单次bump hwm的chunks数增加而导致大量空间的浪费。 

对比AWR可以发现设置44961 level 1024后 enq HW - contention消耗的DB TIME明显减少:
此外在10.2.0.3之前还有一种方案即设置LOB的PCTVERSION 为0/100,但是该方案会导致LOB占用的SPACE大幅上升,所以不推荐,你有大量的理由至少升级DB到10.2.0.5.9。 

通过这个测试用例实验效果,确实设置前后的效果明显:


注意:这里主要看enq HW – contention的优化效果,其他event也有调整优化空间,但不在本文讨论范围。

This entry was posted in Oracle最佳实践 and tagged , , . Bookmark the permalink.