Oracle 块头的事务槽

本文探讨了Oracle数据库中块头的事务槽,强调了INITRANS和MAXTRANS参数的作用,指出每个事务槽对应一个并发事务。实验结果显示,事务槽可能无法扩展,并提出通过增加PCTFREE和INITRANS来防止事务槽不足的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值