首先,这篇文章是基于如下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. [App Store Connect帮助]三、管理 App 和版本(2.3)输入 App 信息:提供自定许可协议

    Apple 提供了适用于所有地区的标准 EULA(最终用户许可协议).如果您不提供自定许可协议,则您的 App 会应用标准 Apple EULA,且该许可协议链接不会显示在您的 App Store 产 ...

  2. Java基础学习经验分享

    很多人学习Java,尤其是自学的人,在学习的过程中会遇到各种各样的问题以及难点,有时候卡在一个点上可能需要很长时间,因为你在自学的过程中不知道如何去掌握和灵活运用以及该注意的点.下面我整理了新手学习可 ...

  3. 如何读取 Json 格式文件

    Json 源文件代码: [ { "Id": "0", "Name": "书籍", "Detail": ...

  4. phonegap在eclipse上的安装

    1.首先安装好eclipse 2.下载安装好sdk 3.下载安装好adt 4.在这个地方下载好phonegap的包,https://codeload.github.com/phonegap/phone ...

  5. EF 批量插入,sqlhelper 批量插入

    需添加一个using System.Linq; 引用 public void BulkInsert<T>(string connection, string tableName, ILis ...

  6. ios数据的基本类型和流程控制

    swift的声明变量方式和js是类似的.基本类型基本都和java的差不多,多了字符类型. let:用于声明常量: var:用于声明变量: 基本类型有:double,float,Int(数字类型):bo ...

  7. C#语言最基础的数组和集合

    数组的书写格式:数据类型[]变量名=new 数据类型[长度]: 集合的书写格式:List<变量类型>变量名=new List<变量类型>(): 集合添加元素:变量名.Add(数 ...

  8. PHP面相对象中的重载与重写

    重写Overriding是父类与子类之间多态性的一种表现,重载Overloading是一个类中多态性的一种表现.Overloaded的方法是可以改变返回值的类型.也就是说,重载的返回值类型可以相同也可 ...

  9. html——特例

    1.a标签与a标签之间有3px距离 2.标准流中的文字不会被浮动的盒子遮挡 <div style="width:150px;height:150px;background-color: ...

  10. 行动起来:转换传统桌面应用程序到UWP 并发布到Windows 应用商店!

    一个月前微软发布了桌面应用程序转换器(Desktop Application Converter),让我们可以把现有的桌面应用程序(.NET 4.6.1 或 Win32)轻松转换成 通用 Window ...