看Concepts不是太理解这两个设置的含义,感觉图不是太容易理解
看完expert one-on-one oracle就比较明白了,顶礼膜拜Thomas ing...
Concepts中有助于理解的部分:
In a newly allocated data block, the space available for inserts is the block size minus the sum of the block overhead and free space (PCTFREE). Updates to existing data can use any available space in the block
这句话比较重要,简单的说data block 上的空闲空间对于insert来说 是有限制的,但对于update是没有限制的,所有的空闲空间都可以。我理解就是只要是table上有free list就可以insert
When you issue an INSERT statement, Oracle checks a free list of the table for the first available data block and uses it if possible.
当提交insert 语句时,Oracle检查表上的Freelist,选择第一个可用的data block使用
The PCTFREE Parameter
The PCTFREE parameter sets the minimum percentage of a data block to be reserved as free space for possible updates to rows that already exist in that block
PCTTREE参数表示的空间比例是用来留给Update的
The PCTUSED Parameter
The PCTUSED parameter sets the minimum percentage of a block that can be used for row data plus overhead before new rows are added to the block
PCTUSED 参数表示的空间比例是用来保证数据头和行数据的空间的
结论:
1 插入的数据很多需要更新,并且更新要增加行的大小。即需要预留给Update的空间比较大,所以PCTFREE需要设置高;且插入数据的到块中都是在空间很大时候才允许,PCTUSED需要设置低。
2 只需要插入和删除。如果将Update的空间留的很多(但实际上并不发生Update),会造成硬盘空间的极大的浪费,PCTFREE需要设置低;PCTUSED设置高是为了,当Update减少行的大小了,那Oracle又会重新增加该数据块到free list中从而被insert的数据使用
3 PCTUSED其实就是针对free list的参数,何时增加free list的。调整这两个参数的目的都是为了减少I/O
实验了下Thomas的例子:
SQL> select * from v$version where rownum<2;
BANNER
----------------------------------------------------------------
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
SQL> show parameter db_block_size;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
db_block_size integer 8192
SQL> set serveroutput on;
设置能在命令行看到dbms output的输出
略去create table 和 create procedure
SQL> exec measure_usage;
insert 00 0 on FREELIST, 0 used by table
insert 01 1 on FREELIST, 1 used by table
insert 02 1 on FREELIST, 1 used by table
insert 03 1 on FREELIST, 1 used by table
insert 04 1 on FREELIST, 1 used by table
insert 05 1 on FREELIST, 1 used by table
insert 06 1 on FREELIST, 1 used by table
insert 07 1 on FREELIST, 1 used by table
insert 08 1 on FREELIST, 2 used by table -- 使用了第二个data block
insert 09 1 on FREELIST, 2 used by table
insert 10 1 on FREELIST, 2 used by table
update 00 1 on FREELIST, 2 used by table
update 01 1 on FREELIST, 2 used by table
update 02 1 on FREELIST, 2 used by table
update 03 1 on FREELIST, 2 used by table
update 04 2 on FREELIST, 2 used by table--恢复了一个free list
update 05 2 on FREELIST, 2 used by table
update 06 2 on FREELIST, 2 used by table
update 07 2 on FREELIST, 2 used by table
update 08 2 on FREELIST, 2 used by table
update 09 2 on FREELIST, 2 used by table
update 10 2 on FREELIST, 2 used by table
PL/SQL 过程已成功完成。
关于dbms_space.free_blocks,以后学习系统包时再详细研究
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22111412/viewspace-610797/ ,如需转载,请注明出处,否则将追究法律责任。