`

关于 db block gets,consistent gets,physical reads的概念

阅读更多

首先来看下官方文档的解释

db block gets:Number of times a CURRENT block was requested. 当前模式所请求读的块数
consistent gets:Number of times a consistent read was requested for a block.   在一致读模式下所读的块数
physical reads:Total number of data blocks read from disk. This number equals the value of "physical reads direct" plus all reads into buffer cache.       从磁盘读的块数 (其大小=物理直接路径读 +从缓冲所获取的块数)

下面来点详细的 其中有些是来自网络上的
觉得还是不够详细,再补充一下:
db block gets :
number of data blocks read in CURRENT mode ie) not in a read consistent fashion, but the current version of the data blocks. 产生db_block_gets的主要方式:
1.DML like Update, Delete will need to access the blocks in the current mode for modification.
2.Most data dictionary calls are done in CURRENT mode.
3.Buffers are often retrieved in current mode for INSERT, UPDATE, and DELETE, and SELECT FOR UPDATE statements. Blocks must be requested in current mode in order to be changed.
4.Also certain classes of blocks, like segment header blocks are always requested in current mode.
5. this will happen when you're doing a FULL TABLE SCAN on a table or a FAST FULL SCAN on an index. In those cases, the segment header is read (usually multiple times for some unknown reason) in current mode.

在current mode模式下产生的对block的访问叫db block gets,这些block在SGA中,不需要访问硬盘。
db_block_gets counts logical reads in CURRENT mode in the buffer cache and also includes direct read blocks (sort-on-disk) blocks.
.
consistent gets :
number of data blocks accessed in READ CONSISTENT mode. When a block is requested in consistent mode, if any changes have been committed or made to that block since the requesting statement (or transaction) began, then they must be rolled back for the purposes of the read, to give a consistent view of the data at that time.(当数据库是在consistent mode模式下被请求的,则假如该数据块的数据修改是在查询语句发出之后被提交的,则此查询语句读到该数据块时,还必须为本次查询将数据回滚,得到查询语句发出时该数据块的值,以便给查询给出一个与该查询有关的所有数据块的一致性视图,这也就是oracle所说的一致性读)   In order to maintain statement level read consistency, Oracle has to read the blocks in a consistent fashion(as of the snapshot SCN) and hence may fetch from rollback segments , which is also added to this statistic. Buffers are usually retrieved in consistent mode for queries. 如普通的select语句、索引访问而引起的将数据读入到buffer中(也可能为physical read)或直接从buffer中读数据。注意,DML语句也能引起consistent gets,如update tab1 set col_b='Hello world' where col_a=1;,因为该语句需要找到需要被修改的所有数据块,在找数据块的过程中就会引起consistent gets。
在Read consistent mode模式下产生的对block的访问叫consistent gets。

Session logical read is: The sum of "db block gets" plus "consistent gets".

db_block_changes:
db_block_changes counts modifications made to CURRENT blocks
'db block changes' = changes made to current blocks under LOGING ( UPDATE, INSERT, DELETE) + changes made to SORT blocks ( NOLOGING).

'consistent changes' :
changes made to block for CONSISTENT READ and changes made to SORT blocks

physical reads :
Physical( disk and/or filesystem page cache) reads. Basically those that cannot be satisfied by the cache and those that are direct reads.
Total number of data blocks read from disk. This number equals the value of "physical reads direct" (direct from disk, excludes buffer cache) plus all reads into buffer cache.


physical writes :
Total number of data blocks written to disk. This number equals the value of "physical writes direct" (Number of writes directly to disk, bypassing the buffer cache as in a direct load operation) plus all writes from buffer cache.

要注意Oracle 的physical read 与 physical writes并不总是等于硬盘真正意义上的物理读与物理写,因为现在都存在操作系统高速缓存与磁盘子系统高速缓存,这样及时I/O没有被实际写入磁盘,操作系统I/O子系统或磁盘系统也会确认为一个成功的I/O,所以ORACLE 的physical read 与 physical writes并不是物理上发生读写的次数。


redo block size:
redo block size is platform specific. There is a method to determine the size by dumping the redo header, refer to note 154864.1. Redo blocks written does not include archive writes or multiplexed writes.

redo entries:
The redo log buffer is a circular buffer in the SGA that holds information about changes made to the database. This information is stored in redo entries. Redo entries contain the information necessary to reconstruct, or redo, changes made to the database . Redo entries are used for database recovery, if necessary.
Redo entries are copied by Oracle server processes from the user's memory space to the redo log buffer in the SGA. (this copy is what the statistic represents).


db block changes包含dml修改的block,也包含为实现rollback功能而修改的block,但是不包含为实现redo功能而修改的block。

the number of blocks visited = consistent gets + db block gets
the number of blocks visited相当与logical read,即从内存中都数据块的次数


这里还有个解释 也很详细 可以综合的看下。。。

A 'consistent get' is your server process telling the database "I need this dba (data block address) consistent with the point in time represented by this SCN, x."

So, lots of things can happen here. First, Oracle will look in the buffer cache for a CR (consistent read) buffer of the block that's consistent w/ the requested SCN. It may find it, if it does, that's counted as a 'consistent get' and either a 'consistent gets - no work' or 'consistent gets - cleanouts only', depending on whether the block needed to be cleaned out. (See V$SYSSTAT/V$SESSTAT for the statistics.) If it doesn't, it may take an existing CR buffer and roll it back further, or it may clone the current block and roll it back. If it needs to apply rollback (aka undo) then it will increment 'consistent gets' and either 'consistent gets - rollbacks only' or 'consistent gets - cleanouts and rollbacks'.

So, each 'consistent get' is your server process successfully getting access to the contents of a dba consistent w/ a particular SCN. This number should represent the number of buffer gets required to satisfy a particular query.

Now, 'db block gets'. A 'db block get' is a copy of the 'current mode block'. That is, the data in the block, as it exists currently, or at this point in time. Note that while multiple CR copies of a block may exist in the buffer cache, there can only ever be one current mode copy of a block in the buffer cache at any one time. (RAC is a special case, w/ shared current and exclusive current, but I'm not going to get into that here.) So, a 'db block get' is a buffer get in current mode. 'db block gets' are usually associated w/ DML, and in that scenario, will implicitly lock one or more rows in that block. Also, there is a notable case where db block gets can occur with a select statement. That will happen when you're doing a FULL TABLE SCAN on a table or a FAST FULL SCAN on an index. In those cases, the segment header is read (usually multiple times for some unknown reason) in current mode.

Next, 'physical reads': A physical read will occur any time a consistent get or a db block get goes looking for block and can't find it in the buffer cache. So, for each block read from disk, physical reads will be incremented. Gets which result in physical reads are counted both as as get and as a read in the statistics. So, if you do 10 consistent gets and 5 of them require physical reads, you should see consistent gets incremented by 10 and physical reads incremented by 5.

Now, what's up w/ arraysize? Well, arraysize is the client side setting for SQL*Plus specifying the size of the array that will receive result sets. The default, as you learned, is 15. Now, suppose you have a table where there are 30 records per block, and 3,000 rows in the table. But, your arraysize is 15. So, your server process will get the first 15 rows, and return them from the first block buffer. Now, for the next 15, you need to get that same block again, for rows 16-30. So, you need to do two buffer gets per block to get all the rows. For a 3,000 row table, you'll do (approximately) 3,000/15 = 200 buffer gets. If you change your arraysize to 30, you can get away w/ visitng each block only once and do 3,000/30 = 100 buffer gets.

So, consider that even after you've optimized a particular SQL statement, if the arraysize is too small, you're going to force your server process to do excess database calls (FETCH calls), and extra buffer gets as well. This can best be illustrated with a test similar to what you did, but try looking at the raw trace file for FETCH calls. The number of FETCH calls ought to be very close to (number of rows returned / arraysize). The 'r=xxx' in the FETCH call data in the trace file is the number of rows returned, which is probably what your arraysize is set to.

So, db block gets, consistent gets, and physical reads are all measured in buffers (or blocks). If the same block is requested multiple times, it will be counted that many times in these statistics. Oracle will always access data from the buffer cache by the buffer. All 'get' operations are by the buffer, never by row. After the buffer is 'gotten', Oracle parses the block to get the data for the relevant rows.


When a "consistent get" is done, this doesn't necessarily mean that Oracle had to do any rollback/undo of DML in order to get the consistent image. Rather, it just means that Oracle requested a copy of the block as of the point in time that the query was started (a "consistent snapshot"). So, I believe it is quite normal to have many, many consistent gets even if there is NO DML occuring.

itpub这里有个关于这方面的一个讨论 biti大师的经典总结

分享到:
评论

相关推荐

    Oracle命中率 笔记整理结合实例

    SQL> SELECT NAME, PHYSICAL_READS, DB_BLOCK_GETS, CONSISTENT_GETS, 1 - (PHYSICAL_READS / (DB_BLOCK_GETS + CONSISTENT_GETS)) "Hit Ratio" FROM V$BUFFER_POOL_STATISTICS WHERE NAME='DEFAULT'; 通常情况下,...

    Oracle性能分析——使用set_autotrace_on和set_timing_on来分析select语句的性能.doc

    统计信息展示了 SQL 语句的执行情况,例如recursive calls、db block gets、consistent gets、physical reads 等;trace 信息展示了 SQL 语句的执行过程。 在分析 autotrace 结果时,需要关注的点包括: * 运行...

    oracle 的Autotrace介绍

    Autotrace Statistics 中有多个常用列,包括 db block gets、consistent gets、physical reads、redo size、sorts (memory) 和 sorts (disk) 等。 在使用 Autotrace 时,需要设置相关的命令,包括 SET AUTOTRACE ...

    数据库调优

    - **计算公式**:`Hit Ratio = 1 - (physical reads / (db block gets + consistent gets))` - 当命中率低于60%~70%时,建议增加`db_block_buffers`的值以扩大缓冲区高速缓存的容量。 3. **调整方法** - `db_...

    Oracle的性能优化.pdf

    通过v$sysstat视图可以监测dbblock gets、consistent gets和physical reads这三个指标。缓冲区的命中率直接影响I/O性能。若物理读取(physical reads)过多,表明命中率低,需要调整缓冲区大小以减少磁盘I/O。 此外...

    SQL Server 数据库的优化及保护.pdf

    计算高速缓冲区命中率的公式为:Hit Ratio = 1 - (physical reads / (db block gets + consistent gets))。对于一般环境,命中率要求大于80%,而在UNIX环境下使用RAW DEVICE时,要求更高,需大于90%。如果命中率低于...

    oracle性能调优之buffer cache

    * 查看 Buffer Cache 的命中率,使用公式 1 - (physical reads cache / consistent gets from cache + db block gets from cache)计算。 * 在多 Buffer Pool 情况下,分别统计不同 Buffer Pool 的命中率。 * 查看...

    阿里巴巴的Oracle DBA笔试题参考答案

    查看该SQL的response time(db block gets/consistent gets/physical reads/sorts)。 六、索引 索引是数据库优化的重要手段。以下是索引相关的知识点: 1. 索引结构:b-tree index、bitmap index、function ...

    DBA笔试题 附答案

    这些指标可以帮助我们判断SQL执行效率,比如如果DB Block Gets和Physical Reads的值很高,可能意味着缓存命中率低,需要进一步优化。 #### 二、索引的理解 索引是提高查询性能的关键技术之一,在Oracle数据库中...

    oracle sga 调整

    计算命中率为:`1 - (physical reads / (db block gets + consistent gets))`。若命中率低于90%,则需增大缓冲区高速缓存的大小。 4. **大型池**:在shared server环境中,大型池用于存储各种共享资源。如果需要...

    Oracle中explain_plan的用法

    2 db block gets 30 consistent gets 0 physical reads 0 redo size 2598 bytes sent via SQL*Net to client 503 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts (memory) 0 ...

    阿里巴巴公司DBA笔试题.doc

    6. **SQL调整关注点**:优化SQL主要关注响应时间,包括DB Block Gets、Consistent Gets、Physical Reads以及Disk Sorts等指标,以减少I/O操作和提高查询效率。 7. **索引的理解**:索引分为B-Tree索引、Bitmap索引...

    oracle 定位sql语句

    6. **SQL调整的关注点**:SQL的响应时间(包括DB Block Gets、Consistent Gets、Physical Reads和Sorts (Disk))是优化的主要关注点,这些指标反映了数据访问、一致性读取、物理I/O以及磁盘排序的开销。 7. **索引...

    Oracle培训讲义(性能分析与调整).docx

    - **db block gets**: 数据块获取次数,反映从数据文件读取的数据块数量。 - **consistent gets**: 一致性读取次数,反映从缓存或数据文件中读取的数据块数量。 - **physical reads**: 物理读取次数,即直接从磁盘...

    如何调整Oracle数据库服务器的性能

    - **缓冲区高速缓存调整**:通过观察`dbblock gets`、`consistent gets`和`physical reads`,分析缓冲区高速缓存的使用情况,如果物理读取次数过多,可能需要增加缓冲区的数量或大小。 3. **调整磁盘I/O** - **...

    第5课 Oracle数据结构(一).pdf

    逻辑读是指从缓存(比如数据缓冲区高速缓存)中读取数据块,包括current reads(DB block gets)和consistent reads。物理读则涉及从磁盘加载数据块到内存。单块读(single block read)对应等待事件“db file ...

    Oracle复习总结

    6. **SQL调整关注点**:关注SQL的响应时间,包括DB Block Gets、Consistent Gets、Physical Reads和Sorts (Disk),这些指标直接影响查询性能。 7. **索引的理解**:索引分为B-Tree索引、Bitmap索引、Function索引和...

    DBA 日常运维经典SQL

    (SUM(DECODE(name, 'db block gets', value, 0)) + SUM(DECODE(name, 'consistent gets', value, 0)))) FROM v$sysstat; 8. Soft parse ratio 该查询语句用于查询当前系统中软解析率,包括软解析次数、总解析...

    显示 sql 执行效率.

    0 db block gets 4 consistent gets 0 physical reads 0 redo size 1310 bytes sent via SQL*Net to client 503 bytes received via SQL*Net from client 2 SQL*Net roundtrips to/from client 0 sorts ...

Global site tag (gtag.js) - Google Analytics