首先,这篇文章是基于如下ORACLE版本。

BANNER
------------------------------------------------
Oracle Database 10g Enterprise Edition Release 1
0.2.0.5.0 - 64bi PL/SQL Release 10.2.0.5.0 - Production
CORE 10.2.0.5.0 Production
TNS for Solaris: Version 10.2.0.5.0 - Production
NLSRTL Version 10.2.0.5.0 - Production

  

下面是x$bh这个视图(也许是表 :)  )  的结构。

X$BH Fixed Table Buffer Cache Diagram

Column     Type Description
~~~~~~ ~~~~~ ~~~~~~~~~~~
ADDR RAW(4) Hex address of the Buffer Header.
INDX NUMBER Buffer Header number
BUF# NUMBER
HLADDR RAW(4) Hash Chain Latch Address
See . ADDR LRU_FLAG NUMBER 8.1+ LRU flag
KCBBHLDF 0x01 8.1 LRU Dump Flag used in debug print routine
KCBBHLMT 0x02 8.1 moved to tail of lru (for extended stats)
KCBBHLAL 0x04 8.1 on auxiliary list
KCBBHLHB 0x08 8.1 hot buffer - not in cold portion of lru FLAG NUMBER
KCBBHFBD 0x00001 buffer dirty
KCBBHFAM 0x00002 7.3 about to modify; try not to start io
KCBBHFAM 0x00002 8.0 about to modify; try not to start io
KCBBHNAC 0x00002 8.1 notify dbwr after change
KCBBHFMS 0x00004 modification started, no new writes
KCBBHFBL 0x00008 block logged
KCBBHFTD 0x00010 temporary data - no redo for changes
KCBBHFBW 0x00020 being written; can't modify
KCBBHFWW 0x00040 waiting for write to finish
KCBBHFCK 0x00080 7.3 checkpoint asap
0x00080 8.0 not used
KCBBHFMW 0x00080 8.1 multiple waiters when gc lock acquired
KCBBHFRR 0x00100 recovery reading, do not reuse, being read
KCBBHFUL 0x00200 unlink from lock element - make non-current
KCBBHFDG 0x00400 write block & stop using for lock down grade
KCBBHFCW 0x00800 write block for cross instance call
KCBBHFCR 0x01000 reading from disk into KCBBHCR buffer
KCBBHFGC 0x02000 has been gotten in current mode
KCBBHFST 0x04000 stale - unused CR buf made from current
0x08000 7.3 Not used.
KCBBHFDP 0x08000 8.0 deferred ping
KCBBHFDP 0x08000 8.1 deferred ping
KCBBHFDA 0x10000 Direct Access to buffer contents
KCBBHFHD 0x20000 Hash chain Dump used in debug print routine
KCBBHFIR 0x40000 Ignore Redo for instance recovery
KCBBHFSQ 0x80000 sequential scan only flag
KCBBHFNW 0x100000 7.3 Set to indicate a buffer that is NEW
0x100000 8.0 Not used
KCBBHFBP 0x100000 8.1 Indicates that buffer was prefetched
KCBBHFRW 0x200000 7.3 re-write if being written (sort)
0x200000 8.0 Not used
KCBBHFFW 0x200000 8.1 Buffer has been written once
KCBBHFFB 0x400000 buffer is "logically" flushed
KCBBHFRS 0x800000 ReSilvered already - do not redirty
KCBBHFKW 0x1000000 7.3 ckpt writing flag to avoid rescan */
0x1000000 8.0 Not used
KCBBHDRC 0x1000000 8.1 buffer is nocache
0x2000000 7.3 Not used
KCBBHFRG 0x2000000 8.0 Redo Generated since block read
KCBBHFRG 0x2000000 8.1 Redo Generated since block read
KCBBHFWS 0x10000000 8.0 Skipped write for checkpoint.
KCBBHFDB 0x20000000 8.1 buffer is directly from a foreign DB
KCBBHFAW 0x40000000 8.0 Flush after writing
KCBBHFAW 0x40000000 8.1 Flush after writing TS# NUMBER 8.X Tablespace number
DBARFIL NUMBER 8.X Relative file number of block
DBAFIL NUMBER 7.3 File number of block
DBABLK NUMBER Block number of block
CLASS NUMBER See Note 33434.1
1,'data block',
2,'sort block',
3,'save undo block',
4,'segment header',
5,'save undo header',
6,'free list',
7,'extent map',
8,'1st level bmb',
9,'2nd level bmb',
10,'3rd level bmb',
11,'bitmap block',
12,'bitmap index block',
13,'file header block',
14,'unused',
15,'system undo header',
16,'system undo block',
17,'undo header',
18,'undo block' -- since 10g STATE NUMBER
KCBBHFREE 0 buffer free
KCBBHEXLCUR 1 buffer current (and if DFS locked X)
KCBBHSHRCUR 2 buffer current (and if DFS locked S)
KCBBHCR 3 buffer consistant read
KCBBHREADING 4 Being read
KCBBHMRECOVERY 5 media recovery (current & special)
KCBBHIRECOVERY 6 Instance recovery (somewhat special) MODE_HELD NUMBER Mode buffer held in (MODE pre 7.3)
0=KCBMNULL, KCBMSHARE, KCBMEXCL CHANGES NUMBER
CSTATE NUMBER
X_TO_NULL NUMBER Count of PINGS out (OPS)
DIRTY_QUEUE NUMBER You wont normally see buffers on the LRUW
LE_ADDR RAW(4) Lock Element address (OPS)
SET_DS RAW(4) Buffer cache set this buffer is under
OBJ NUMBER Data object number
TCH NUMBER 8.1 Touch Count
TIM NUMBER 8.1 Touch Time
BA RAW(4)
CR_SCN_BAS NUMBER Consistent Read SCN base
CR_SCN_WRP NUMBER Consistent Read SCN wrap
CR_XID_USN NUMBER CR XID Undo segment no
CR_XID_SLT NUMBER CR XID slot
CR_XID_SQN NUMBER CR XID Sequence
CR_UBA_FIL NUMBER CR UBA file
CR_UBA_BLK NUMBER CR UBA Block
CR_UBA_SEQ NUMBER CR UBA sequence
CR_UBA_REC NUMBER CR UBA record
CR_SFL NUMBER
LRBA_SEQ NUMBER } Lowest RBA needed to recover block in cache
LRBA_BNO NUMBER }
LRBA_BOF NUMBER } HRBA_SEQ NUMBER } Redo RBA to be flushed BEFORE this block
HRBA_BNO NUMBER } can be written out
HRBA_BOF NUMBER } RRBA_SEQ NUMBER } Block recovery RBA
RRBA_BNO NUMBER }
RRBA_BOF NUMBER }
NXT_HASH NUMBER Next buffer on this hash chain
PRV_HASH NUMBER Previous buffer on this hash chain
NXT_LRU NUMBER Next buffer on the LRU
PRV_LRU NUMBER Previous buffer on the LRU
US_NXT RAW(4)
US_PRV RAW(4)
WA_NXT RAW(4)
WA_PRV RAW(4)
ACC RAW(4)
MOD RAW(4)

  

看不懂没关系,这个视图就是oracle data buffer的一个窗口。里面的每一条记录代表了data buffer中的一个记录。

下面的查询可以查到data buffer中有哪些数据对象的data block以及他们占用多少buffer。这里限定了表空间号大于2是为了除去一些系统表占用的buffer。

SQL> select
2 o.owner owner, o.object_name, blsiz , count(*) blocks
3 from x$bh b , dba_objects o
4 where b.obj = o.data_object_id
5 and b.ts# > 2
6 group by o.owner,o.object_name, blsiz
7 order by blocks desc; OWNER OBJECT_NAME BLSIZ BLOCKS
------------------ ------------------------------------------------ ---------- ----------
SATTEST AUDIT_LOG 8192 404
CITOSADMIN RMS_AUDIT_LOG 8192 68
CICOSADMIN BERTH_ALLOCATION 8192 14
CITOSADMIN EAS_DOCUMENT_DETAIL 8192 10
CITOSADMIN TEST 8192 8
CITOSADMIN TERMINAL2 8192 5
CITOSADMIN EAS_CONFIG 8192 5
CICOSADMIN BERTH_ALLOCATION_NNDX4 8192 4
CITOSADMIN SITE 8192 3
CICOSADMIN BERTH_ALLOCATION_NNDX3 8192 3
CITOSADMIN TERMINAL 8192 3
CICOSADMIN BERTH_ALLOCATION_NNDX2 8192 3
CICOSADMIN BERTH_ALLOCATION_NNDX1 8192 3
CITOSADMIN REEFER_PAYMENT_SCHEME 8192 1
CITOSADMIN CNTR 8192 1
SUMSADMIN SM_DISCHARGING_LIST 8192 1
CITOSADMIN CNTR_2 8192 1
CITOSADMIN GATE_PM_TRIP 8192 1

下面的查询可以查到data buffer中的某个数据对象(这里叫TEST)其占用的buffer的状态。这里看到TEST有两个cr块和6个xcur块。关于各个block的状态,cr是用于consistent read的。xcur表示是最新的块,scur也是最新的块,但scur存在于RAC中表示多个instance共享这个block。free很好理解,是可以被重用的块。

SQL>  select
o.object_name
2 3 ,decode(state,0,'free',1,'xcur',2,'scur',3,'cr', 4,'read',5,'mrec'
4 ,6,'irec',7,'write',8,'pi') state
5 , blsiz , count(*) blocks
6 from x$bh b , dba_objects o
7 where b.obj = o.data_object_id
8 and b.ts# > 0
9 and o.object_name = 'TEST'
10 group by o.object_name, state, blsiz; OBJECT_NAME STATE BLSIZ BLOCKS
------------------------------------------------ --------------- ---------- ----------
TEST cr 8192 2
TEST xcur 8192 6

下面的查询查到data buffer中特定数据对象不同状态buffer的地址信息,DBARFIL是相对文件号,是每个表空间中确定datafile的文件号,DBABLK是确定文件号后确定datablock的block number。BA是该buffer的实际addr

SQL> select
2 o.object_name
3 ,decode(state,0,'free',1,'xcur',2,'scur',3,'cr', 4,'read',5,'mrec',6,'irec',7,'write',8,'pi') state
4 , dbarfil
5 , dbablk
6 , ba
7 from x$bh b , dba_objects o
8 where b.obj = o.data_object_id
9 and b.ts# > 0
10 and o.object_name = 'TEST'
11 ; OBJECT_NAME STATE DBARFIL DBABLK BA
------------------------------------------------ --------------- ---------- ---------- ----------------
TEST xcur 4 61470 000000038A380000
TEST xcur 4 61467 00000003866EA000
TEST xcur 4 61472 0000000385E5E000
TEST cr 4 61469 000000038BF08000
TEST cr 4 61469 0000000386F20000
TEST xcur 4 61469 000000038186C000
TEST xcur 4 61471 0000000399D5E000
TEST xcur 4 61468 0000000381716000

下面做一些操作以便熟悉该视图。

首先创建一个表如下:

create table test (id1 number,id2 number,text varchar2(2000));
insert into citosadmin.test values(1,1,'a');
insert into citosadmin.test values(2,2,'b');
insert into citosadmin.test values(3,3,'c');
alter system flush buffer_cache;

  

然后看一下data buffer中这个表占用的情况。占用了6个buffer

SQL> select o.owner owner, o.object_name, blsiz , count(*) blocks from x$bh b , dba_objects o
2 where b.obj = o.data_object_id and o.object_name='TEST' group by o.owner,o.object_name, blsiz; OWNER OBJECT_NAME BLSIZ BLOCKS
------------------ ------------------------------------------------ ---------- ----------
CITOSADMIN TEST 8192 6

全都是xcur状态的。xcur是表示是current的最新的block。如果是rac block和其它的instance共享则是scur。

SQL>  select
2 o.object_name
3 ,decode(state,0,'free',1,'xcur',2,'scur',3,'cr', 4,'read',5,'mrec'
4 ,6,'irec',7,'write',8,'pi') state
5 , blsiz , count(*) blocks
6 from x$bh b , dba_objects o
7 where b.obj = o.data_object_id
8 and b.ts# > 0
9 and o.object_name = 'TEST'
10 group by o.object_name, state, blsiz; OBJECT_NAME STATE BLSIZ BLOCKS
------------------------------------------------ --------------- ---------- ----------
TEST xcur 8192 6

每个buffer的地址如下

SQL> select o.object_name
2 ,decode(state,0,'free',1,'xcur',2,'scur',3,'cr', 4,'read',5,'mrec',6,'irec',7,'write',8,'pi') state
3 , dbarfil
4 , dbablk
5 , ba
6 from x$bh b , dba_objects o
7 where b.obj = o.data_object_id
8 and o.object_name = 'TEST'; OBJECT_NAME STATE DBARFIL DBABLK BA
------------------------------------------------ --------------- ---------- ---------- ----------------
TEST xcur 4 61478 00000003816BC000
TEST xcur 4 61475 0000000389494000
TEST xcur 4 61480 000000039CEB8000
TEST xcur 4 61477 000000039CD8A000
TEST xcur 4 61479 000000038DDD8000
TEST xcur 4 61476 000000038AB52000

为了使用GV$BH视图,对上述SQL做了些更改,下面列出了使用gv$bh视图的sql语句,两两一组,上面是用x$bh下面是用gv$bh

select INST_ID, o.owner owner, o.object_name, blsiz , count(*) blocks from x$bh b , dba_objects o where b.obj = o.data_object_id and o.object_name='T' group by INST_ID, o.owner,o.object_name, blsiz;

col OBJECT_NAME for a20
col OWNER for a8
select INST_ID, o.owner owner, o.object_name, count(*) blocks from gv$bh b , dba_objects o where b.objd = o.data_object_id and o.object_name='T' group by INST_ID, o.owner,o.object_name ; ------------------------------------------------------------------
select
INST_ID,
o.object_name,
decode(state,0,'free',1,'xcur',2,'scur',3,'cr', 4,'read',5,'mrec',6,'irec',7,'write',8,'pi') state,
blsiz ,
count(*) blocks
from x$bh b , dba_objects o
where b.obj = o.data_object_id and o.object_name = 'T' group by INST_ID,o.object_name, state, blsiz; select
INST_ID,
o.object_name,
b.STATUS,
count(*) blocks
from gv$bh b , dba_objects o
where b.objd = o.data_object_id and o.object_name = 'T' group by INST_ID,o.object_name, b.STATUS ;
------------------------------------------------------------------
select
INST_ID,
o.object_name,
decode(state,0,'free',1,'xcur',2,'scur',3,'cr', 4,'read',5,'mrec',6,'irec',7,'write',8,'pi') state,
dbarfil,
dbablk,
ba
from x$bh b , dba_objects o
where b.obj = o.data_object_id and o.object_name = 'T'; select
INST_ID,
o.object_name,
b.status,
FILE# ,
BLOCK#
from gv$bh b , dba_objects o
where b.objd = o.data_object_id and o.object_name = 'T';
------------------------------------------------------------------

x$bh视图的更多相关文章

  1. oracle视图V$BH && X$BH的使用列子

    1创建一个测试表,test,并且插入10000行数据:    SQL>  create table test (id int); SQL> begin      2  for i in 1 ...

  2. oracle rac理解和用途扩展

    Oracle RAC的优势在于利用多个节点(数据库实例)组成一个数据库,这样在保证了数据库高可用性的情况下更充分的利用了多个主机的性能,而且可以通过增加节点进行性能的扩展.实现Oracle RAC需要 ...

  3. Oracle buffer cache与相关的latch等待事件

    buffer cache与相关的latch等待事件 1.buffer cache 2.latch:cache buffers lru chain 3.latch:cache buffers chain ...

  4. orace owi介绍

    第1章 OWI介绍记录和观察进程所经历的等待现象的功能和界面以及方法论,统称为OWI,也就是Oracle Wait Interface.等待事件的P1.P2.P3值可以通过v$session_wait ...

  5. 热点块引发的cache buffers cahins latch

    热点块引发的Cache buffer Chains latch: SQL语句即便适当进行了调优,有时也无法解决cache buffers cahins latch,若在编写SQL语句时的SQL工作方式 ...

  6. Latch free等待事件

    Latch free等待事件的三个参数:p1-latch的地址:p2-latch编号:p3-请求次数.从oracle10g起,latchfree不再包含所有的latch等待,有些latch等待可能表现 ...

  7. Oracle 体系结构二 内存结构

    Oracle实例由共享内存块(SGA)以及大量的后台进程构成. SGA必须包含的数据结构: 数据库缓冲区缓存 日志缓冲区 共享池 可选的数据结构: 大池 JAVA池 流池 其他缓冲区缓存池 用户会话还 ...

  8. global cache cr request

    当一个进程访问需要一个或者多个块时,它会首先检查自己的CACHE是否存在该块,如果发现没有,就会先通过global cache赋予这些块 共享访问的权限,然后再访问.假如,通过global cache ...

  9. db file sequential read等待事件 --转载

    db file sequential read db file sequential read等待事件有3个参数:file#,first block#,和block数量.在10g中,这等待事件受到用户 ...

随机推荐

  1. yii登陆中添加验证码

    1.在SiteController中添加如下代码: /** * Declares class-based actions. */ public function actions() { return  ...

  2. codevs1036商务旅行(LCA)

    1036 商务旅行  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 某首都城市的商人要经常到各城镇去做 ...

  3. [App Store Connect帮助]二、 添加、编辑和删除用户(5)创建一个沙盒测试员帐户

    如果您的 App 使用了 App 内购买项目或 Apple Pay,您可以在 App Store Connect 中创建沙盒测试员帐户,以便您向用户提供该 App 前,可以使用该帐户在测试环境中运行您 ...

  4. [Swift通天遁地]四、网络和线程-(2)通过BlockOperation实现线程的队列

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  5. c的二级指针

    ----"c 语言的精华在于指针的灵活性.学好指针的目的在于尽可能少的使用指针." 在敲binary search tree(二叉查找树),遇到了问题.在删除的时候,如果删除的是r ...

  6. [转]Linux rpm 命令参数使用详解

    转自:http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/10/08/2203153.html RPM是RedHat Package Mana ...

  7. js 计算时间差

    function GetDateDiff(startDate,endDate) { var startTime = new (<any>Date)(Date.parse(startDate ...

  8. 再战primer——decltype 和引用

    刷primer看到原文讲到"引用从来都作为其所指对象的同义词出现,只有用在decltype处是一个例外.",我很是好奇. 这个“引用”当然是指引用类型,like this: ; i ...

  9. Objective-C——Runtime理解

    动态语言 OC是一门不折不扣的动态语言,所以它的很多机制都是动态运行时决定的.这点和C语言不一样,C语言是静态绑定,也就是编译后所有的一切都已经决定了.这一点和C语言的函数指针有些类似,很多时候函数指 ...

  10. [ SHOI 2001 ] 化工厂装箱员

    \(\\\) \(Description\) 传送带上按顺序传过来\(N\)个物品,一个有\(A,B,C\)三类. 每次装箱员手里只能至多拿十个,然后将手中三类物品中的一类装箱,才能接着拿或接着装箱, ...