Oracle 塊頭的事務槽

INITRANS 初始個數,默認爲2,每個塊會預分配2個事務槽。
MAXTRANS 事務槽的最大個數,爲255(新版本已經不可設置了)。
事務槽的增加是需要空間的,如果塊上空間不足,事務槽的數量將達不到255。
每個事務槽代表一個併發事務。

探索小實驗:

SCOTT@ prod> create table t ( x int primary key , y varchar2(4000) ) ;

Table created.

SCOTT@ prod> insert into t(x,y) select rownum , rpad('*' , 148 , '*') from dual connect by level <= 46 ;

46 rows created.

SCOTT@ prod> select length(y) , dbms_rowid.rowid_block_number(rowid) blk , count(*) , min(x) , max(x)
  2  from t group by length(y) , dbms_rowid.rowid_block_number(rowid) ;

 LENGTH(Y)        BLK   COUNT(*)     MIN(X)     MAX(X)
---------- ---------- ---------- ---------- ----------
       148     462572         46          1         46

SCOTT@ prod>
SCOTT@ prod> commit ;

Commit complete.

SCOTT@ prod> create or replace procedure do_update(p_n in number)
  2  as
  3  pragma autonomous_transaction ;
  4  l_rec t%rowtype ;
  5  resource_busy exception ;
  6  pragma exception_init(resource_busy , -54) ;
  7  begin
  8  select * into l_rec from t
  9  where x = p_n
 10  for update nowait ;
 11  
 12  do_update(p_n + 1 ) ;
 13  commit ;
 14  exception
 15  when resource_busy
 16  then
 17  dbms_output.put_line('locked out trying to select row' || p_n ) ;
 18  commit ;
 19  when no_data_found
 20  then
 21  dbms_output.put_line('we finished - no problems') ;
 22  commit ;
 23  end ;
 24  /

Procedure created.

SCOTT@ prod>
SCOTT@ prod> exec do_update(1) ;
locked out trying to select row38

PL/SQL procedure successfully completed.

SCOTT@ prod>
SCOTT@ prod>
SCOTT@ prod>
SCOTT@ prod> truncate table t ;

Table truncated.

SCOTT@ prod> insert into t(x,y) select rownum , rpad('*' , 147 , '*') from dual connect by level <= 46 ;

46 rows created.

SCOTT@ prod> select length(y) , dbms_rowid.rowid_block_number(rowid) blk , count(*) , min(x) , max(x)
  2  from t group by length(y) , dbms_rowid.rowid_block_number(rowid) ;

 LENGTH(Y)        BLK   COUNT(*)     MIN(X)     MAX(X)
---------- ---------- ---------- ---------- ----------
       147     462572         46          1         46

SCOTT@ prod> exec do_update(1) ;
we finished - no problems

PL/SQL procedure successfully completed.

實驗表明:

事務槽有不能擴展的可能性。
46個字節就可以增加9個以上的事務槽。

爲了防止事務槽不足:

增加PCTFREE。
增加INITRANS。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章