对373472.1中脚本的一点解释

| 6 Comments

"Script to Identify Objects and Amount of Blocks in the Buffer Pools - Default, Keep, Recycle, nK Cache [ID 373472.1]"用到了一个查询脚本,这个脚本的内容为:

select decode(pd.bp_id,1,'KEEP',2,'RECYCLE',3,'DEFAULT',

         4,'2K SUBCACHE',5,'4K SUBCACHE',6,'8K SUBCACHE',

         7,'16K SUBCACHE',8,'32KSUBCACHE','UNKNOWN') subcache,

         bh.object_name,bh.blocks

from x$kcbwds ds,x$kcbwbpd pd,(select /*+ use_hash(x) */ set_ds,

         o.name object_name,count(*) BLOCKS

         from obj$ o, x$bh x where o.dataobj# = x.obj

         and x.state !=0 and o.owner# !=0

         group by set_ds,o.name) bh

where ds.set_id >= pd.bp_lo_sid

and ds.set_id <= pd.bp_hi_sid

and pd.bp_size != 0

and ds.addr=bh.set_ds;

 

上述脚本用来定位哪些objectbuffer cache中存在,占用的buffer cache的量是多少以及占用的是什么类型的buffer cache

 

我们现在来用一下上述脚本:

SQL> select decode(pd.bp_id,1,'KEEP',2,'RECYCLE',3,'DEFAULT',

  2           4,'2K SUBCACHE',5,'4K SUBCACHE',6,'8K SUBCACHE',

  3           7,'16K SUBCACHE',8,'32KSUBCACHE','UNKNOWN') subcache,

  4           bh.object_name,bh.blocks

  5  from x$kcbwds ds,x$kcbwbpd pd,(select /*+ use_hash(x) */ set_ds,

  6           o.name object_name,count(*) BLOCKS

  7           from obj$ o, x$bh x where o.dataobj# = x.obj

  8           and x.state !=0 and o.owner# !=0

  9           group by set_ds,o.name) bh

 10  where ds.set_id >= pd.bp_lo_sid

 11  and ds.set_id <= pd.bp_hi_sid

 12  and pd.bp_size != 0

 13  and ds.addr=bh.set_ds order by bh.blocks desc;

 

SUBCACHE     OBJECT_NAME                        BLOCKS

------------ ------------------------------ ----------

DEFAULT      MGMT_SEVERITY                        4688

DEFAULT      UPLLKT                               4471

DEFAULT      SEVERITY_PRIMARY_KEY                 2829

DEFAULT      UPLTER                               2707

DEFAULT      UPLBCR                               2267

DEFAULT      SALWAT                               1825

DEFAULT      OWBATN                               1763

DEFAULT      MGMT_SEVERITY_IDX_03                  753

DEFAULT      IDX_UPLTER_UTETKT                     626

DEFAULT      MGMT_METRICS_1HOUR_PK                 377

DEFAULT      OWBWTK                                377

DEFAULT      MGMT_METRICS_RAW_PK                   370

DEFAULT      SALDRT                                187

DEFAULT      SALDAT                                137

DEFAULT      SALBTH                                125

DEFAULT      MGMT_SYSTEM_PERFORMANCE_LOG           104

DEFAULT      MGMT_METRICS_1DAY_PK                  101

DEFAULT      MGMT_METRICS                           81

DEFAULT      IDX_SALWAT_SWABTH                      81

DEFAULT      IWBCTK                                 66

......省略显示部分内容

DEFAULT      MGMT_CURRENT_SEVERITY_IDX_01            1

DEFAULT      MGMT_DB_FEATUREUSAGE_PK                 1

 

SQL> alter system flush buffer_cache;

 

System altered

 

SQL> select decode(pd.bp_id,1,'KEEP',2,'RECYCLE',3,'DEFAULT',

  2           4,'2K SUBCACHE',5,'4K SUBCACHE',6,'8K SUBCACHE',

  3           7,'16K SUBCACHE',8,'32KSUBCACHE','UNKNOWN') subcache,

  4           bh.object_name,bh.blocks

  5  from x$kcbwds ds,x$kcbwbpd pd,(select /*+ use_hash(x) */ set_ds,

  6           o.name object_name,count(*) BLOCKS

  7           from obj$ o, x$bh x where o.dataobj# = x.obj

  8           and x.state !=0 and o.owner# !=0

  9           group by set_ds,o.name) bh

 10  where ds.set_id >= pd.bp_lo_sid

 11  and ds.set_id <= pd.bp_hi_sid

 12  and pd.bp_size != 0

 13  and ds.addr=bh.set_ds order by bh.blocks desc;

 

SUBCACHE     OBJECT_NAME                        BLOCKS

------------ ------------------------------ ----------

 

现在我们来研究一下上述脚本的含义是什么?

 

里面主要涉及到了x$kcbwds x$kcbwbpdx$bhx$bh的含义我相信大家都清楚,但是另外两个(即x$kcbwds x$kcbwbpd)的含义是什么呢?

 

答案是----我也不知道,而且这里你也不用去metalink上查了,oracle一般不会把这种internal的东西公开

 

但是,即便在不清楚上述x$视图含义的情况下,还是可以来分析上述脚本的,我们来看一下分析的过程:

 

在我执行了下述两条sql后:

select * from v$fixed_view_definition where view_definition like '%x$kcbwds%';

select * from v$fixed_view_definition where view_definition like '%x$kcbwbpd%';

 

结果显示x$kcbwds x$kcbwbpd只和GV$BUFFER_POOL_STATISTICS有关,且上述查询结果显示GV$BUFFER_POOL_STATISTICS的创建语句为:

select kcbwbpd.inst_id, kcbwbpd.bp_id, kcbwbpd.bp_name, kcbwbpd.bp_blksz, sum(kcbwds.cnum_set),

sum(kcbwds.cnum_repl), sum(kcbwds.cnum_write), sum(kcbwds.cnum_set), sum(kcbwds.buf_got),

sum(kcbwds.sum_wrt), sum(kcbwds.sum_scn), sum(kcbwds.fbwait), sum(kcbwds.wcwait), sum(kcbwds.bbwait),

sum(kcbwds.fbinsp), sum(kcbwds.dbinsp), sum(kcbwds.dbbchg), sum(kcbwds.dbbget), sum(kcbwds.conget),

sum(kcbwds.pread), sum(kcbwds.pwrite)

from x$kcbwds kcbwds, x$kcbwbpd kcbwbpd

where kcbwds.set_id >= kcbwbpd.bp_lo_sid

and kcbwds.set_id <= kcbwbpd.bp_hi_sid

and kcbwbpd.bp_size != 0

group by kcbwbpd.inst_id, kcbwbpd.bp_id, kcbwbpd.bp_name, kcbwbpd.bp_blksz

看到上述结果中蓝色字体表示的部分了吗?注意看,这里和上述查询脚本中用蓝色字体标注出来的限制条件是一样的。

 

即上述查询脚本实际上就是利用了V$BUFFER_POOL_STATISTICS

而且因为上述脚本用到了x$bh中的set_dsx$kcbwds中的addr关联,所以不能直接用V$BUFFER_POOL_STATISTICSV$BHV$BUFFER_POOL_STATISTICS里没有字段addrv$bh中也没有字段set_ds),也就是说这里只能用x$视图关联。

x$bh中的set_ds的含义为"Buffer cache set this buffer is under"。

 

好了,分析到这里,上述脚本的含义我们已经清楚了,翻译过来就是:

首先关联x$bhobj$,找到buffer cache中那些不属于sys用户且状态不是freeblock,并且按照这些block所在的buffer cache set与所属的object namegroup by.

然后用上述group by的结果与V$BUFFER_POOL_STATISTICS的基表x$kcbwds x$kcbwbpd做关联,关联条件除了V$BUFFER_POOL_STATISTIC本身所需的条件外(即上述脚本中蓝色字体标注的部分),还加上了buffer cache set应该相同。

 

对于oracle提供的脚本,我们应该尽量在自己能力所及的范围内不仅知其然,也知其所以然。

6 Comments

hua,我顶你~~~

一点疑惑:我在10.2.0.4上试了一下,发现同一object下会跨多个set,也就是在返回结果中会发现多个相同的object。

更改了一下,对object加上group:

select decode(pd.bp_id,1,'KEEP',2,'RECYCLE',3,'DEFAULT',
4,'2K SUBCACHE',5,'4K SUBCACHE',6,'8K SUBCACHE',
7,'16K SUBCACHE',8,'32KSUBCACHE','UNKNOWN') subcache,
bh.object_name, sum(bh.blocks) total_blocks
from x$kcbwds ds,x$kcbwbpd pd,(select /*+ use_hash(x) */ set_ds,
o.name object_name,count(*) BLOCKS
from obj$ o, x$bh x where o.dataobj# = x.obj
and x.state !=0 and o.owner# !=0
group by set_ds,o.name) bh
where ds.set_id >= pd.bp_lo_sid
and ds.set_id <= pd.bp_hi_sid
and pd.bp_size != 0
and ds.addr=bh.set_ds
group by pd.bp_id, bh.object_name
order by total_blocks;

大师意见如何?

可以啊,我觉得你这样没问题。
对了,你的sql里有“and ds.set_id and pd.bp_size != 0”,这个是你的笔误吧?

应该不是,copy过来的,估计是大于号被当作html的tag了。。。

我终于明白x$kcbwds,x$kcbwbpd以及上述蓝色字体标注的含义了。

Leave a comment

Recent Comments

  • cui hua: 我终于明白x$kcbwds,x$kcbwbpd以及上述蓝色字体标注的含义了。 read more
  • Ericcn: 应该不是,copy过来的,估计是大于号被当作html的tag了。。。 read more
  • cui hua: 可以啊,我觉得你这样没问题。 对了,你的sql里有“and ds.set_id and pd.bp_size != 0”,这个是你的笔误吧? read more
  • Ericcn: 一点疑惑:我在10.2.0.4上试了一下,发现同一object下会跨多个set,也就是在返回结果中会发现多个相同的object。 更改了一下,对object加上group: select decode(pd.bp_id,1,'KEEP',2,'RECYCLE',3,'DEFAULT', 4,'2K SUBCACHE',5,'4K SUBCACHE',6,'8K SUBCACHE', 7,'16K SUBCACHE',8,'32KSUBCACHE','UNKNOWN') read more
  • cui hua: 谢谢:) read more
  • jlttt: hua,我顶你~~~ read more

About this Entry

This page contains a single entry by cui hua published on January 7, 2010 3:41 PM.

Metalink上也许会有我的一篇文章 was the previous entry in this blog.

如何通过修改数据字典来恢复被truncate的数据 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.