Oracle 块头的事务槽

来源:互联网 发布:linux数据库备份命令 编辑:程序博客网 时间:2024/06/09 15:30

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         46SCOTT@ 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 row38PL/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         46SCOTT@ prod> exec do_update(1) ;we finished - no problemsPL/SQL procedure successfully completed.

实验表明:

事务槽有不能扩展的可能性。
46个字节就可以增加9个以上的事务槽。

为了防止事务槽不足:

增加PCTFREE。
增加INITRANS。

原创粉丝点击