从Oracle 隐含参数_db_block_max_cr_dba引伸开去
今天偶尔看到一个隐含参数_db_block_max_cr_dba,Oracle对它的解释是 Maximum Allowed Number of CR buffers per dba其默认值是6。
尽管是周末,一时手痒对其做一把测试,看看究竟是干嘛用的。
数据库版本为
SQL> select * from v$version where rownum<2;
BANNER
----------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
创建一张测试表
SQL> conn zhou/zhou
Connected.
SQL> create table testcr as select
SQL> create table testcr (id number);
Table created.
获得测试表testcr的file和block
SQL> select dbms_rowid.ROWID_RELATIVE_FNO(rowid) file_id,dbms_rowid.ROWID_BLOCK_NUMBER(rowid) block_no from testcr;
FILE_ID BLOCK_NO
---------- ----------
7 39213
SQL> select status,count(*) from v$bh where file#=7 and block#=39213 group by status;
STATUS COUNT(*)
------- ----------
xcur 1
现在会话一执行update不提交
SQL> update testcr set id=2;
1 row updated.
会话二执行
SQL> select * from testcr;
ID
----------
1
会话一查看内存中该block的情况
SQL> select status,count(*) from v$bh where file#=7 and block#=39213 group by status;
STATUS COUNT(*)
------- ----------
xcur 1
cr 3
在会话二多次查询该表格,继续在会话一查看内存中该block的情况,发现xcur+cr刚好等于6即隐含参数_db_block_max_cr_dba值
SQL> select status,count(*) from v$bh where file#=7 and block#=39213 group by status;
STATUS COUNT(*)
------- ----------
xcur 1
cr 5
如果在会话一查询
SQL> select * from testcr;
ID
----------
2
可以发现cr从5变为4,将会话二的cr版本置换出去
SQL> select status,count(*) from v$bh where file#=7 and block#=39213 group by status;
STATUS COUNT(*)
------- ----------
xcur 1
cr 4
先将事务回滚
SQL> rollback;
Rollback complete.
SQL> select status,count(*) from v$bh where file#=7 and block#=39213 group by status;
STATUS COUNT(*)
------- ----------
xcur 1
cr 4
如果将内存刷出会发生什么事情呢
SQL> alter system flush buffer_cache;
System altered.
可以看到cr 状态变为free。
SQL> select status,count(*) from v$bh where file#=7 and block#=39213 group by status;
STATUS COUNT(*)
------- ----------
free 4
再次在会话一中查询,可以看到产生一个xcur块。
SQL> select status,count(*) from v$bh where file#=7 and block#=39213 group by status;
STATUS CO