db_block_checking和db_block_chec…
来源:互联网 发布:sql清除两天前的数据 编辑:程序博客网 时间:2024/05/18 00:30
先看看Oracle文档上对db_block_checking参数的说明:
DB_BLOCK_CHECKING controls whether Oracle performs block checkingfor data blocks. When this parameter is set to true, Oracleperforms block checking for all data blocks. When it is set tofalse, Oracle does not perform. block checking for blocks in theuser tablespaces. However, block checking for theSYSTEM tablespaceis always turned on.
Oracle checks a block by going through the data on the block,making sure it is self-consistent. Block checking can often preventmemory and data corruption. Block checking typically causes 1% to10% overhead, depending on workload. The more updates or inserts ina workload, the more expensive it is to turn on block checking. Youshould set DB_BLOCK_CHECKING to trueif the performance overhead isacceptable
从文档中可以看到,DB_BLOCK_CHECKING参数主要是用于数据块的逻辑(一致)检查(但只是块内,不包括块间的逻辑检查,比如索引项目的ROWID指向的是不存在的行等)。
主要用于防止在内存中损坏或数据损坏。由于是逻辑检查,因此引起的额外负荷比较高,甚至可以达到10%,因此对于一个繁忙的系统,特别是插入或更新操作很多的系统,性能影响是比较明显的。
该参数对SYSTEM表空间始终是处于“打开”状态,而不管该参数是否设置为FALSE。
下面再看看db_block_checksum参数的说明:
DB_BLOCK_CHECKSUM determines whether DBWn and the direct loaderwill calculate a checksum(a number calculated from all the bytesstored in the block) and store it in the cache header of every datablock when writing it to disk. Checksums are verified when a blockis read-only if this parameter is true and thelast write of the block stored a checksum. Inaddition, Oracle gives every log block a checksum before writing itto the current log.
If this parameter is set to false, DBWn calculates checksums onlyfor the SYSTEM tablespace, but not for user tablespaces.
Checksums allow Oracle to detect corruption caused by underlyingdisks, storage systems, or I/O systems. Turning on this featuretypically causes only an additional 1% to 2% overhead. Therefore,Oracle Corporation recommends that you set DB_BLOCK_CHECKSUM totrue
可以看到,DB_BLOCK_CHECKSUM只是在写入(DBWn常规写法或用户进程直接路径写入),根据一个CHECKSUM算法,计算数据块的校验和。然后写入数据块的一个特定位置(CACHEHEADER,具体是块的16-17字节,以0字节起算)。在读取块时,再进行检验。主要是防止IO硬件和IO子系统的错误。
CHECKSUM的算法只是根据块的字节值计算一个效验和,因此算法比较简单,引起的系统额外负荷通常在1%-2%
实际上,即使将该参数设为TRUE,将数据块(包括SYSTEM表空间)的16-17字节清0,同时将15字节(flag),第3位(即值为16进制0x04)清为0,则在块读取时也不会做CHECKSUM检查。如果该参数为FALSE,对于除SYSTEM的其他表空间,如果原来有CHECKSUM值,将15-16字节清0也不会做CHECKSUM检查。
db_block_checking和db_block_checksum这参数设置
在Oracle 10gR2版本之后db_block_checking和db_block_checksum这两个参数有了新的变化
先来看看db_block_checking,这个参数现在有四个可能的设置:
OFF - 与原来的FALSE一样,对非SYSTEM表空间的块关闭检查,这个值在设置时仍然可以用false。
LOW -只检查块头。这个检查发生在当块的内容在内存中发生改变时,比如UPDATE、INSERT、DELETE等,以及将块从磁盘读入、RAC结点间块的传输。
MEDIUM - 比LOW更高一级,还包括了非IOT的表的块内部检查(即不仅仅是块头)。
FULL - 与原来的TRUE一样,与MEDIUM相比,还包括了索引块的检查。
再看看db_block_checksum这个参数有什么变化:
OFF - 与原来的FALSE一样,只会给SYSTEM表空间的块计算checksum值。
TYPICAL - 与原来的TRUE一样,Oracle在向磁盘写入块时计算checksum值,下次读入时进行校验。
FULL -这是新增的值,Oracle不仅在写入块时计算checksum值,而且在更改块(比如执行UPDATE语句等)之前对checksum值进行校验,同时在更改块之后对checksum值进行重新计算。另外Oracle也会在写入日志块时,计算块的checksum。这个设置大大增加了系统负荷,大约带来了4-5%的负荷。而TYPICAL值会带来1-2%的负荷。
db_block_checking的性能花销及测试
Oracle官方文档对db_block_checking各个参数设置的性能花销是有如下数据
full – see above depending on updates and insertsand how well the database is tuned it can be costly 10%
medium – midrange but can be up to 10%.
low – very low around 1 %
off – no overhead
测试过程
SQL> create table MACLEAN(t1 int,t2 char(20),t3char(20),t4 char(20), t5 char(20),t6 date) tablespace users;
Table created.
SQL> create or replace procedureinsert_data(s int) as
2 begin
3 for i in1..s loop
4 insert into MACLEAN values(i,'A','B','C','D',sysdate);
5 commit;
6 end loop;
7 end;
8 /
Procedure created.
SQL>show parameter db_block_checking
NAME TYPE VALUE
----------------------------------- ----------- ------------------------------
db_block_checking string FALSE
SQL> begin
2
3 insert_data(50000);
4 end;
5 /
SQL> truncate tableMACLEAN;
SQL>alter system flushbuffer_cache;
begin
insert_data(100000);
end;
/
truncate table MACLEAN;
alter system flush buffer_cache;
begin
insert_data(150000);
end;
/
truncate table MACLEAN;
alter system flush buffer_cache;
将db_block_checking设置未true
SQL> begin
2
3 insert_data(50000);
4 end;
5 /
SQL> truncate tableMACLEAN;
SQL>alter system flushbuffer_cache;
begin
insert_data(100000);
end;
/
truncate table MACLEAN;
alter system flush buffer_cache;
begin
insert_data(150000);
end;
/
truncate table MACLEAN;
alter system flush buffer_cache;
查看消耗的cpu时间
SQL> col sql_text for a70;
SQL> select sql_text, cpu_time, elapsed_time
2 from v$sql
3 where sql_text like'%CHECKING%'
4 and sql_text not like'%v$sql%'
5 order by CPU_TIME;
SQL_TEXT
DB_BLOCK_CHECKING controls whether Oracle performs block checkingfor data blocks. When this parameter is set to true, Oracleperforms block checking for all data blocks. When it is set tofalse, Oracle does not perform. block checking for blocks in theuser tablespaces. However, block checking for theSYSTEM tablespaceis always turned on.
Oracle checks a block by going through the data on the block,making sure it is self-consistent. Block checking can often preventmemory and data corruption. Block checking typically causes 1% to10% overhead, depending on workload. The more updates or inserts ina workload, the more expensive it is to turn on block checking. Youshould set DB_BLOCK_CHECKING to trueif the performance overhead isacceptable
从文档中可以看到,DB_BLOCK_CHECKING参数主要是用于数据块的逻辑(一致)检查(但只是块内,不包括块间的逻辑检查,比如索引项目的ROWID指向的是不存在的行等)。
主要用于防止在内存中损坏或数据损坏。由于是逻辑检查,因此引起的额外负荷比较高,甚至可以达到10%,因此对于一个繁忙的系统,特别是插入或更新操作很多的系统,性能影响是比较明显的。
该参数对SYSTEM表空间始终是处于“打开”状态,而不管该参数是否设置为FALSE。
下面再看看db_block_checksum参数的说明:
DB_BLOCK_CHECKSUM determines whether DBWn and the direct loaderwill calculate a checksum(a number calculated from all the bytesstored in the block) and store it in the cache header of every datablock when writing it to disk. Checksums are verified when a blockis read-only if this parameter is true and thelast
If this parameter is set to false, DBWn calculates checksums onlyfor the SYSTEM tablespace, but not for user tablespaces.
Checksums allow Oracle to detect corruption caused by underlyingdisks, storage systems, or I/O systems. Turning on this featuretypically causes only an additional 1% to 2% overhead. Therefore,Oracle Corporation recommends that you set DB_BLOCK_CHECKSUM totrue
可以看到,DB_BLOCK_CHECKSUM只是在写入(DBWn常规写法或用户进程直接路径写入),根据一个CHECKSUM算法,计算数据块的校验和。然后写入数据块的一个特定位置(CACHEHEADER,具体是块的16-17字节,以0字节起算)。在读取块时,再进行检验。主要是防止IO硬件和IO子系统的错误。
CHECKSUM的算法只是根据块的字节值计算一个效验和,因此算法比较简单,引起的系统额外负荷通常在1%-2%
实际上,即使将该参数设为TRUE,将数据块(包括SYSTEM表空间)的16-17字节清0,同时将15字节(flag),第3位(即值为16进制0x04)清为0,则在块读取时也不会做CHECKSUM检查。如果该参数为FALSE,对于除SYSTEM的其他表空间,如果原来有CHECKSUM值,将15-16字节清0也不会做CHECKSUM检查。
db_block_checking和db_block_checksum这参数设置
在Oracle 10gR2版本之后db_block_checking和db_block_checksum这两个参数有了新的变化
先来看看db_block_checking,这个参数现在有四个可能的设置:
OFF - 与原来的FALSE一样,对非SYSTEM表空间的块关闭检查,这个值在设置时仍然可以用false。
LOW -只检查块头。这个检查发生在当块的内容在内存中发生改变时,比如UPDATE、INSERT、DELETE等,以及将块从磁盘读入、RAC结点间块的传输。
MEDIUM - 比LOW更高一级,还包括了非IOT的表的块内部检查(即不仅仅是块头)。
FULL - 与原来的TRUE一样,与MEDIUM相比,还包括了索引块的检查。
再看看db_block_checksum这个参数有什么变化:
OFF - 与原来的FALSE一样,只会给SYSTEM表空间的块计算checksum值。
TYPICAL - 与原来的TRUE一样,Oracle在向磁盘写入块时计算checksum值,下次读入时进行校验。
FULL -这是新增的值,Oracle不仅在写入块时计算checksum值,而且在更改块(比如执行UPDATE语句等)之前对checksum值进行校验,同时在更改块之后对checksum值进行重新计算。另外Oracle也会在写入日志块时,计算块的checksum。这个设置大大增加了系统负荷,大约带来了4-5%的负荷。而TYPICAL值会带来1-2%的负荷。
db_block_checking的性能花销及测试
Oracle官方文档对db_block_checking各个参数设置的性能花销是有如下数据
full – see above depending on updates and insertsand how well the database is tuned it can be costly 10%
medium – midrange but can be up to 10%.
low – very low around 1 %
off – no overhead
测试过程
SQL> create table MACLEAN(t1 int,t2 char(20),t3char(20),t4 char(20), t5 char(20),t6 date) tablespace users;
Table created.
SQL> create or replace
Procedure created.
SQL>show
NAME
-----------------------------------
db_block_checking
SQL> begin
将db_block_checking设置未true
查看消耗的cpu时间
SQL> col sql_text for a70;
SQL> select sql_text, cpu_time, elapsed_time
SQL_TEXT